Skip to content

Commit 7c6f637

Browse files
committed
fix(incrementalDelivery): remove extra then from AsyncRecord completion
extracted from #3786
1 parent 7a609a2 commit 7c6f637

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

src/execution/__tests__/stream-test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,6 @@ describe('Execute: stream directive', () => {
531531
},
532532
],
533533
},
534-
],
535-
hasNext: true,
536-
},
537-
{
538-
incremental: [
539534
{
540535
items: [{ name: 'Leia', id: '3' }],
541536
path: ['friendList', 2],
@@ -984,11 +979,6 @@ describe('Execute: stream directive', () => {
984979
},
985980
],
986981
},
987-
],
988-
hasNext: true,
989-
},
990-
{
991-
incremental: [
992982
{
993983
items: [{ nonNullName: 'Han' }],
994984
path: ['friendList', 2],

src/execution/execute.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,16 +1791,21 @@ function executeDeferredFragment(
17911791
fields,
17921792
asyncPayloadRecord,
17931793
);
1794-
1795-
if (isPromise(promiseOrData)) {
1796-
promiseOrData = promiseOrData.then(null, (e) => {
1797-
asyncPayloadRecord.errors.push(e);
1798-
return null;
1799-
});
1800-
}
18011794
} catch (e) {
18021795
asyncPayloadRecord.errors.push(e);
1803-
promiseOrData = null;
1796+
asyncPayloadRecord.addData(null);
1797+
return;
1798+
}
1799+
1800+
if (isPromise(promiseOrData)) {
1801+
promiseOrData.then(
1802+
(value) => asyncPayloadRecord.addData(value),
1803+
(error) => {
1804+
asyncPayloadRecord.errors.push(error);
1805+
asyncPayloadRecord.addData(null);
1806+
},
1807+
);
1808+
return;
18041809
}
18051810
asyncPayloadRecord.addData(promiseOrData);
18061811
}
@@ -1823,7 +1828,7 @@ function executeStreamField(
18231828
exeContext,
18241829
});
18251830
if (isPromise(item)) {
1826-
const completedItems = completePromisedValue(
1831+
completePromisedValue(
18271832
exeContext,
18281833
itemType,
18291834
fieldNodes,
@@ -1832,15 +1837,14 @@ function executeStreamField(
18321837
item,
18331838
asyncPayloadRecord,
18341839
).then(
1835-
(value) => [value],
1840+
(value) => asyncPayloadRecord.addItems([value]),
18361841
(error) => {
18371842
asyncPayloadRecord.errors.push(error);
18381843
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
1839-
return null;
1844+
asyncPayloadRecord.addItems(null);
18401845
},
18411846
);
18421847

1843-
asyncPayloadRecord.addItems(completedItems);
18441848
return asyncPayloadRecord;
18451849
}
18461850

@@ -1885,15 +1889,14 @@ function executeStreamField(
18851889
return handledError;
18861890
})
18871891
.then(
1888-
(value) => [value],
1892+
(value) => asyncPayloadRecord.addItems([value]),
18891893
(error) => {
18901894
asyncPayloadRecord.errors.push(error);
18911895
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
1892-
return null;
1896+
asyncPayloadRecord.addItems(null);
18931897
},
18941898
);
18951899

1896-
asyncPayloadRecord.addItems(completedItems);
18971900
return asyncPayloadRecord;
18981901
}
18991902

@@ -2008,22 +2011,19 @@ async function executeStreamIterator(
20082011

20092012
const { done, value: completedItem } = iteration;
20102013

2011-
let completedItems: PromiseOrValue<Array<unknown> | null>;
20122014
if (isPromise(completedItem)) {
2013-
completedItems = completedItem.then(
2014-
(value) => [value],
2015+
completedItem.then(
2016+
(resolvedItem) => asyncPayloadRecord.addItems([resolvedItem]),
20152017
(error) => {
20162018
asyncPayloadRecord.errors.push(error);
20172019
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
2018-
return null;
2020+
asyncPayloadRecord.addItems(null);
20192021
},
20202022
);
20212023
} else {
2022-
completedItems = [completedItem];
2024+
asyncPayloadRecord.addItems([completedItem]);
20232025
}
20242026

2025-
asyncPayloadRecord.addItems(completedItems);
2026-
20272027
if (done) {
20282028
break;
20292029
}
@@ -2202,7 +2202,7 @@ class DeferredFragmentRecord {
22022202
});
22032203
}
22042204

2205-
addData(data: PromiseOrValue<ObjMap<unknown> | null>) {
2205+
addData(data: ObjMap<unknown> | null) {
22062206
const parentData = this.parentContext?.promise;
22072207
if (parentData) {
22082208
this._resolve?.(parentData.then(() => data));
@@ -2253,7 +2253,7 @@ class StreamRecord {
22532253
});
22542254
}
22552255

2256-
addItems(items: PromiseOrValue<Array<unknown> | null>) {
2256+
addItems(items: Array<unknown> | null) {
22572257
const parentData = this.parentContext?.promise;
22582258
if (parentData) {
22592259
this._resolve?.(parentData.then(() => items));

0 commit comments

Comments
 (0)