@@ -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 ,
@@ -265,7 +268,7 @@ class IncrementalPublisher {
265
268
if ( reconcilableResults === undefined ) {
266
269
continue ;
267
270
}
268
- const id = deferredFragmentRecord . id ;
271
+ const id = this . _ids . get ( deferredFragmentRecord ) ;
269
272
invariant ( id !== undefined ) ;
270
273
const incremental = context . incremental ;
271
274
for ( const reconcilableResult of reconcilableResults ) {
@@ -283,6 +286,7 @@ class IncrementalPublisher {
283
286
}
284
287
incremental . push ( incrementalEntry ) ;
285
288
}
289
+ this . _ids . delete ( deferredFragmentRecord ) ;
286
290
context . completed . push ( { id } ) ;
287
291
}
288
292
}
@@ -292,9 +296,10 @@ class IncrementalPublisher {
292
296
context : SubsequentIncrementalExecutionResultContext ,
293
297
) : void {
294
298
const streamRecord = streamItemsResult . streamRecord ;
295
- const id = streamRecord . id ;
299
+ const id = this . _ids . get ( streamRecord ) ;
296
300
invariant ( id !== undefined ) ;
297
301
if ( streamItemsResult . errors !== undefined ) {
302
+ this . _ids . delete ( streamRecord ) ;
298
303
context . completed . push ( {
299
304
id,
300
305
errors : streamItemsResult . errors ,
@@ -309,6 +314,7 @@ class IncrementalPublisher {
309
314
} ) ;
310
315
}
311
316
} else if ( streamItemsResult . result === undefined ) {
317
+ this . _ids . delete ( streamRecord ) ;
312
318
context . completed . push ( { id } ) ;
313
319
this . _incrementalGraph . removeStream ( streamRecord ) ;
314
320
if ( isCancellableStreamRecord ( streamRecord ) ) {
@@ -344,7 +350,7 @@ class IncrementalPublisher {
344
350
if ( deferredFragmentRecord === initialDeferredFragmentRecord ) {
345
351
continue ;
346
352
}
347
- const id = deferredFragmentRecord . id ;
353
+ const id = this . _ids . get ( deferredFragmentRecord ) ;
348
354
// TODO: add test case for when an fragment has not been released, but might be processed for the shortest path.
349
355
/* c8 ignore next 3 */
350
356
if ( id === undefined ) {
0 commit comments