diff --git a/src/execution/IncrementalPublisher.ts b/src/execution/IncrementalPublisher.ts index d09802f6528..d41b95aaa89 100644 --- a/src/execution/IncrementalPublisher.ts +++ b/src/execution/IncrementalPublisher.ts @@ -584,10 +584,15 @@ export class IncrementalPublisher { } if (isStreamItemsRecord(subsequentResultRecord)) { if (subsequentResultRecord.isFinalRecord) { - newPendingSources.delete(subsequentResultRecord.streamRecord); - completedResults.push( - this._completedRecordToResult(subsequentResultRecord.streamRecord), - ); + if (newPendingSources.has(subsequentResultRecord.streamRecord)) { + newPendingSources.delete(subsequentResultRecord.streamRecord); + } else { + completedResults.push( + this._completedRecordToResult( + subsequentResultRecord.streamRecord, + ), + ); + } } if (subsequentResultRecord.isCompletedAsyncIterator) { // async iterable resolver just finished but there may be pending payloads @@ -650,10 +655,13 @@ export class IncrementalPublisher { ); } } else { - newPendingSources.delete(subsequentResultRecord); - completedResults.push( - this._completedRecordToResult(subsequentResultRecord), - ); + if (newPendingSources.has(subsequentResultRecord)) { + newPendingSources.delete(subsequentResultRecord); + } else { + completedResults.push( + this._completedRecordToResult(subsequentResultRecord), + ); + } if (subsequentResultRecord.errors.length > 0) { continue; } diff --git a/src/execution/__tests__/defer-test.ts b/src/execution/__tests__/defer-test.ts index 653297ff76a..24087da0bbb 100644 --- a/src/execution/__tests__/defer-test.ts +++ b/src/execution/__tests__/defer-test.ts @@ -1188,11 +1188,7 @@ describe('Execute: defer directive', () => { path: ['hero', 'nestedObject', 'deeperObject'], }, ], - completed: [ - { path: ['hero'] }, - { path: ['hero', 'nestedObject'] }, - { path: ['hero', 'nestedObject', 'deeperObject'] }, - ], + completed: [{ path: ['hero'] }], hasNext: false, }, ]); @@ -1256,7 +1252,6 @@ describe('Execute: defer directive', () => { completed: [ { path: ['hero'] }, { path: ['hero', 'nestedObject', 'deeperObject'] }, - { path: ['hero', 'nestedObject', 'deeperObject'] }, ], hasNext: false, }, @@ -2062,12 +2057,7 @@ describe('Execute: defer directive', () => { path: ['hero'], }, ], - completed: [ - { path: ['hero'] }, - { path: ['hero', 'friends', 0] }, - { path: ['hero', 'friends', 1] }, - { path: ['hero', 'friends', 2] }, - ], + completed: [{ path: ['hero'] }], hasNext: false, }, ]); diff --git a/src/execution/__tests__/stream-test.ts b/src/execution/__tests__/stream-test.ts index 32f7e310ca1..a1b217815ab 100644 --- a/src/execution/__tests__/stream-test.ts +++ b/src/execution/__tests__/stream-test.ts @@ -355,8 +355,6 @@ describe('Execute: stream directive', () => { completed: [ { path: ['friendList'] }, { path: ['friendList', 0, 'appearsIn'] }, - { path: ['friendList', 1, 'appearsIn'] }, - { path: ['friendList', 2, 'appearsIn'] }, ], hasNext: false, }, @@ -404,15 +402,7 @@ describe('Execute: stream directive', () => { path: ['friendList', 0], }, ], - completed: [ - { path: ['friendList', 0] }, - { path: ['friendList'] }, - { path: ['friendList', 1] }, - { path: ['friendList', 2] }, - { path: ['friendList', 0, 'appearsIn'] }, - { path: ['friendList', 1, 'appearsIn'] }, - { path: ['friendList', 2, 'appearsIn'] }, - ], + completed: [{ path: ['friendList', 0] }, { path: ['friendList'] }], hasNext: false, }, ]);