@@ -93,15 +93,15 @@ export interface FormattedSubsequentIncrementalExecutionResult<
93
93
extensions ?: TExtensions ;
94
94
}
95
95
96
- interface RawDeferResult < TData = ObjMap < unknown > > {
96
+ interface BareDeferredGroupedFieldSetResult < TData = ObjMap < unknown > > {
97
97
errors ?: ReadonlyArray < GraphQLError > ;
98
98
data : TData ;
99
99
}
100
100
101
101
export interface IncrementalDeferResult <
102
102
TData = ObjMap < unknown > ,
103
103
TExtensions = ObjMap < unknown > ,
104
- > extends RawDeferResult < TData > {
104
+ > extends BareDeferredGroupedFieldSetResult < TData > {
105
105
id : string ;
106
106
subPath ?: ReadonlyArray < string | number > ;
107
107
extensions ?: TExtensions ;
@@ -118,15 +118,15 @@ export interface FormattedIncrementalDeferResult<
118
118
extensions ?: TExtensions ;
119
119
}
120
120
121
- interface RawStreamItemsResult < TData = ReadonlyArray < unknown > > {
121
+ interface BareStreamItemsResult < TData = ReadonlyArray < unknown > > {
122
122
errors ?: ReadonlyArray < GraphQLError > ;
123
123
items : TData ;
124
124
}
125
125
126
126
export interface IncrementalStreamResult <
127
127
TData = ReadonlyArray < unknown > ,
128
128
TExtensions = ObjMap < unknown > ,
129
- > extends RawStreamItemsResult < TData > {
129
+ > extends BareStreamItemsResult < TData > {
130
130
id : string ;
131
131
subPath ?: ReadonlyArray < string | number > ;
132
132
extensions ?: TExtensions ;
@@ -175,10 +175,14 @@ export function buildIncrementalResponse(
175
175
context : IncrementalPublisherContext ,
176
176
result : ObjMap < unknown > ,
177
177
errors : ReadonlyArray < GraphQLError > | undefined ,
178
- futures : ReadonlyArray < Future > ,
178
+ incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ,
179
179
) : ExperimentalIncrementalExecutionResults {
180
180
const incrementalPublisher = new IncrementalPublisher ( context ) ;
181
- return incrementalPublisher . buildResponse ( result , errors , futures ) ;
181
+ return incrementalPublisher . buildResponse (
182
+ result ,
183
+ errors ,
184
+ incrementalDataRecords ,
185
+ ) ;
182
186
}
183
187
184
188
interface IncrementalPublisherContext {
@@ -195,7 +199,7 @@ class IncrementalPublisher {
195
199
private _context : IncrementalPublisherContext ;
196
200
private _nextId : number ;
197
201
private _pending : Set < SubsequentResultRecord > ;
198
- private _completedResultQueue : Array < FutureResult > ;
202
+ private _completedResultQueue : Array < IncrementalDataRecordResult > ;
199
203
private _newPending : Set < SubsequentResultRecord > ;
200
204
private _incremental : Array < IncrementalResult > ;
201
205
private _completed : Array < CompletedResult > ;
@@ -217,9 +221,9 @@ class IncrementalPublisher {
217
221
buildResponse (
218
222
data : ObjMap < unknown > ,
219
223
errors : ReadonlyArray < GraphQLError > | undefined ,
220
- futures : ReadonlyArray < Future > ,
224
+ incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ,
221
225
) : ExperimentalIncrementalExecutionResults {
222
- this . _addFutures ( futures ) ;
226
+ this . _addIncrementalDataRecords ( incrementalDataRecords ) ;
223
227
this . _pruneEmpty ( ) ;
224
228
225
229
const pending = this . _pendingSourcesToResults ( ) ;
@@ -235,14 +239,16 @@ class IncrementalPublisher {
235
239
} ;
236
240
}
237
241
238
- private _addFutures ( futures : ReadonlyArray < Future > ) : void {
239
- for ( const future of futures ) {
240
- if ( isDeferredGroupedFieldSetRecord ( future ) ) {
241
- for ( const deferredFragmentRecord of future . deferredFragmentRecords ) {
242
+ private _addIncrementalDataRecords (
243
+ incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ,
244
+ ) : void {
245
+ for ( const incrementalDataRecord of incrementalDataRecords ) {
246
+ if ( isDeferredGroupedFieldSetRecord ( incrementalDataRecord ) ) {
247
+ for ( const deferredFragmentRecord of incrementalDataRecord . deferredFragmentRecords ) {
242
248
this . _addDeferredFragmentRecord ( deferredFragmentRecord ) ;
243
249
}
244
250
245
- const result = future . result ;
251
+ const result = incrementalDataRecord . result ;
246
252
if ( isPromise ( result ) ) {
247
253
// eslint-disable-next-line @typescript-eslint/no-floating-promises
248
254
result . then ( ( resolved ) => {
@@ -255,12 +261,12 @@ class IncrementalPublisher {
255
261
continue ;
256
262
}
257
263
258
- const streamRecord = future . streamRecord ;
264
+ const streamRecord = incrementalDataRecord . streamRecord ;
259
265
if ( streamRecord . id === undefined ) {
260
266
this . _newPending . add ( streamRecord ) ;
261
267
}
262
268
263
- const result = future . getResult ( ) ;
269
+ const result = incrementalDataRecord . getResult ( ) ;
264
270
if ( isPromise ( result ) ) {
265
271
// eslint-disable-next-line @typescript-eslint/no-floating-promises
266
272
result . then ( ( resolved ) => {
@@ -383,7 +389,7 @@ class IncrementalPublisher {
383
389
while ( ! isDone ) {
384
390
let pending : Array < PendingResult > = [ ] ;
385
391
386
- let completedResult : FutureResult | undefined ;
392
+ let completedResult : IncrementalDataRecordResult | undefined ;
387
393
while (
388
394
( completedResult = this . _completedResultQueue . shift ( ) ) !== undefined
389
395
) {
@@ -514,8 +520,10 @@ class IncrementalPublisher {
514
520
) ;
515
521
}
516
522
517
- if ( deferredGroupedFieldSetResult . futures ) {
518
- this . _addFutures ( deferredGroupedFieldSetResult . futures ) ;
523
+ if ( deferredGroupedFieldSetResult . incrementalDataRecords ) {
524
+ this . _addIncrementalDataRecords (
525
+ deferredGroupedFieldSetResult . incrementalDataRecords ,
526
+ ) ;
519
527
}
520
528
521
529
for ( const deferredFragmentRecord of deferredGroupedFieldSetResult . deferredFragmentRecords ) {
@@ -608,8 +616,10 @@ class IncrementalPublisher {
608
616
609
617
this . _incremental . push ( incrementalEntry ) ;
610
618
611
- if ( streamItemsResult . futures ) {
612
- this . _addFutures ( streamItemsResult . futures ) ;
619
+ if ( streamItemsResult . incrementalDataRecords ) {
620
+ this . _addIncrementalDataRecords (
621
+ streamItemsResult . incrementalDataRecords ,
622
+ ) ;
613
623
this . _pruneEmpty ( ) ;
614
624
}
615
625
}
@@ -655,16 +665,16 @@ export function isDeferredFragmentRecord(
655
665
}
656
666
657
667
export function isDeferredGroupedFieldSetRecord (
658
- future : Future ,
659
- ) : future is DeferredGroupedFieldSetRecord {
660
- return future instanceof DeferredGroupedFieldSetRecord ;
668
+ incrementalDataRecord : IncrementalDataRecord ,
669
+ ) : incrementalDataRecord is DeferredGroupedFieldSetRecord {
670
+ return incrementalDataRecord instanceof DeferredGroupedFieldSetRecord ;
661
671
}
662
672
663
673
export interface IncrementalContext {
664
674
deferUsageSet : DeferUsageSet | undefined ;
665
675
path : Path | undefined ;
666
676
errors ?: Map < Path | undefined , GraphQLError > | undefined ;
667
- futures ?: Array < Future > | undefined ;
677
+ incrementalDataRecords ?: Array < IncrementalDataRecord > | undefined ;
668
678
}
669
679
670
680
export type DeferredGroupedFieldSetResult =
@@ -680,8 +690,8 @@ export function isDeferredGroupedFieldSetResult(
680
690
interface ReconcilableDeferredGroupedFieldSetResult {
681
691
deferredFragmentRecords : ReadonlyArray < DeferredFragmentRecord > ;
682
692
path : Array < string | number > ;
683
- result : RawDeferResult ;
684
- futures ?: ReadonlyArray < Future > | undefined ;
693
+ result : BareDeferredGroupedFieldSetResult ;
694
+ incrementalDataRecords ?: ReadonlyArray < IncrementalDataRecord > | undefined ;
685
695
sent ?: true | undefined ;
686
696
}
687
697
@@ -785,14 +795,14 @@ interface NonReconcilableStreamItemsResult {
785
795
786
796
interface NonTerminatingStreamItemsResult {
787
797
streamRecord : StreamRecord ;
788
- result : RawStreamItemsResult ;
789
- futures ?: ReadonlyArray < Future > | undefined ;
798
+ result : BareStreamItemsResult ;
799
+ incrementalDataRecords ?: ReadonlyArray < IncrementalDataRecord > | undefined ;
790
800
}
791
801
792
802
interface TerminatingStreamItemsResult {
793
803
streamRecord : StreamRecord ;
794
804
result ?: never ;
795
- futures ?: never ;
805
+ incrementalDataRecords ?: never ;
796
806
errors ?: never ;
797
807
}
798
808
@@ -848,14 +858,21 @@ export class StreamItemsRecord {
848
858
this . nextStreamItems !== undefined
849
859
? {
850
860
...result ,
851
- futures : [ this . nextStreamItems , ...( result . futures ?? [ ] ) ] ,
861
+ incrementalDataRecords : [
862
+ this . nextStreamItems ,
863
+ ...( result . incrementalDataRecords ?? [ ] ) ,
864
+ ] ,
852
865
}
853
866
: result ;
854
867
}
855
868
}
856
869
857
- export type Future = DeferredGroupedFieldSetRecord | StreamItemsRecord ;
870
+ export type IncrementalDataRecord =
871
+ | DeferredGroupedFieldSetRecord
872
+ | StreamItemsRecord ;
858
873
859
- export type FutureResult = DeferredGroupedFieldSetResult | StreamItemsResult ;
874
+ export type IncrementalDataRecordResult =
875
+ | DeferredGroupedFieldSetResult
876
+ | StreamItemsResult ;
860
877
861
878
type SubsequentResultRecord = DeferredFragmentRecord | StreamRecord ;
0 commit comments