@@ -60,11 +60,13 @@ interface SubsequentIncrementalExecutionResultContext {
60
60
*/
61
61
class IncrementalPublisher {
62
62
private _context : IncrementalPublisherContext ;
63
+ private _ids : Map < SubsequentResultRecord , string > ;
63
64
private _nextId : number ;
64
65
private _incrementalGraph : IncrementalGraph ;
65
66
66
67
constructor ( context : IncrementalPublisherContext ) {
67
68
this . _context = context ;
69
+ this . _ids = new Map ( ) ;
68
70
this . _nextId = 0 ;
69
71
this . _incrementalGraph = new IncrementalGraph ( ) ;
70
72
}
@@ -96,7 +98,7 @@ class IncrementalPublisher {
96
98
const pendingResults : Array < PendingResult > = [ ] ;
97
99
for ( const pendingSource of newPending ) {
98
100
const id = String ( this . _getNextId ( ) ) ;
99
- pendingSource . id = id ;
101
+ this . _ids . set ( pendingSource , id ) ;
100
102
const pendingResult : PendingResult = {
101
103
id,
102
104
path : pathToArray ( pendingSource . path ) ,
@@ -232,14 +234,15 @@ class IncrementalPublisher {
232
234
) {
233
235
for ( const deferredFragmentRecord of deferredGroupedFieldSetResult
234
236
. deferredGroupedFieldSetRecord . deferredFragmentRecords ) {
235
- const id = deferredFragmentRecord . id ;
236
237
if (
237
238
! this . _incrementalGraph . removeDeferredFragment ( deferredFragmentRecord )
238
239
) {
239
240
// This can occur if multiple deferred grouped field sets error for a fragment.
240
241
continue ;
241
242
}
243
+ const id = this . _ids . get ( deferredFragmentRecord ) ;
242
244
invariant ( id !== undefined ) ;
245
+ this . _ids . delete ( deferredFragmentRecord ) ;
243
246
context . completed . push ( {
244
247
id,
245
248
errors : deferredGroupedFieldSetResult . errors ,
@@ -266,7 +269,7 @@ class IncrementalPublisher {
266
269
if ( reconcilableResults === undefined ) {
267
270
continue ;
268
271
}
269
- const id = deferredFragmentRecord . id ;
272
+ const id = this . _ids . get ( deferredFragmentRecord ) ;
270
273
invariant ( id !== undefined ) ;
271
274
const incremental = context . incremental ;
272
275
for ( const reconcilableResult of reconcilableResults ) {
@@ -284,6 +287,7 @@ class IncrementalPublisher {
284
287
}
285
288
incremental . push ( incrementalEntry ) ;
286
289
}
290
+ this . _ids . delete ( deferredFragmentRecord ) ;
287
291
context . completed . push ( { id } ) ;
288
292
}
289
293
}
@@ -293,9 +297,10 @@ class IncrementalPublisher {
293
297
context : SubsequentIncrementalExecutionResultContext ,
294
298
) : void {
295
299
const streamRecord = streamItemsResult . streamRecord ;
296
- const id = streamRecord . id ;
300
+ const id = this . _ids . get ( streamRecord ) ;
297
301
invariant ( id !== undefined ) ;
298
302
if ( streamItemsResult . errors !== undefined ) {
303
+ this . _ids . delete ( streamRecord ) ;
299
304
context . completed . push ( {
300
305
id,
301
306
errors : streamItemsResult . errors ,
@@ -310,6 +315,7 @@ class IncrementalPublisher {
310
315
} ) ;
311
316
}
312
317
} else if ( streamItemsResult . result === undefined ) {
318
+ this . _ids . delete ( streamRecord ) ;
313
319
context . completed . push ( { id } ) ;
314
320
this . _incrementalGraph . removeStream ( streamRecord ) ;
315
321
if ( isCancellableStreamRecord ( streamRecord ) ) {
@@ -345,7 +351,7 @@ class IncrementalPublisher {
345
351
if ( deferredFragmentRecord === initialDeferredFragmentRecord ) {
346
352
continue ;
347
353
}
348
- const id = deferredFragmentRecord . id ;
354
+ const id = this . _ids . get ( deferredFragmentRecord ) ;
349
355
// TODO: add test case for when an fragment has not been released, but might be processed for the shortest path.
350
356
/* c8 ignore next 3 */
351
357
if ( id === undefined ) {
0 commit comments