Skip to content

Commit e5d982f

Browse files
committed
use complete helpers within completeListItemValue
The optimized helpers change the order of promise resolution and affect the value of hasNext.
1 parent 91bc8c0 commit e5d982f

File tree

2 files changed

+23
-48
lines changed

2 files changed

+23
-48
lines changed

src/execution/__tests__/stream-test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ describe('Execute: stream directive', () => {
483483
},
484484
],
485485
},
486+
],
487+
hasNext: true,
488+
},
489+
{
490+
incremental: [
486491
{
487492
items: [{ name: 'Leia', id: '3' }],
488493
path: ['friendList', 2],

src/execution/execute.ts

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,6 @@ async function completeAsyncIteratorValue(
10921092
completeListItemValue(
10931093
iteration.value,
10941094
completedResults,
1095-
errors,
10961095
exeContext,
10971096
itemType,
10981097
fieldNodes,
@@ -1122,7 +1121,6 @@ function completeListValue(
11221121
asyncPayloadRecord?: AsyncPayloadRecord,
11231122
): PromiseOrValue<ReadonlyArray<unknown>> {
11241123
const itemType = returnType.ofType;
1125-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
11261124

11271125
if (isAsyncIterable(result)) {
11281126
const iterator = result[Symbol.asyncIterator]();
@@ -1181,7 +1179,6 @@ function completeListValue(
11811179
completeListItemValue(
11821180
item,
11831181
completedResults,
1184-
errors,
11851182
exeContext,
11861183
itemType,
11871184
fieldNodes,
@@ -1207,68 +1204,41 @@ function completeListValue(
12071204
function completeListItemValue(
12081205
item: unknown,
12091206
completedResults: Array<unknown>,
1210-
errors: Array<GraphQLError>,
12111207
exeContext: ExecutionContext,
12121208
itemType: GraphQLOutputType,
12131209
fieldNodes: ReadonlyArray<FieldNode>,
12141210
info: GraphQLResolveInfo,
12151211
itemPath: Path,
12161212
asyncPayloadRecord?: AsyncPayloadRecord,
12171213
): boolean {
1218-
try {
1219-
let completedItem;
1220-
if (isPromise(item)) {
1221-
completedItem = item.then((resolved) =>
1222-
completeValue(
1223-
exeContext,
1224-
itemType,
1225-
fieldNodes,
1226-
info,
1227-
itemPath,
1228-
resolved,
1229-
asyncPayloadRecord,
1230-
),
1231-
);
1232-
} else {
1233-
completedItem = completeValue(
1214+
if (isPromise(item)) {
1215+
completedResults.push(
1216+
completePromiseCatchingErrors(
12341217
exeContext,
12351218
itemType,
12361219
fieldNodes,
12371220
info,
12381221
itemPath,
12391222
item,
12401223
asyncPayloadRecord,
1241-
);
1242-
}
1243-
1244-
if (isPromise(completedItem)) {
1245-
// Note: we don't rely on a `catch` method, but we do expect "thenable"
1246-
// to take a second callback for the error case.
1247-
completedResults.push(
1248-
completedItem.then(undefined, (rawError) => {
1249-
const error = locatedError(
1250-
rawError,
1251-
fieldNodes,
1252-
pathToArray(itemPath),
1253-
);
1254-
const handledError = handleFieldError(error, itemType, errors);
1255-
filterSubsequentPayloads(exeContext, itemPath, asyncPayloadRecord);
1256-
return handledError;
1257-
}),
1258-
);
1224+
),
1225+
);
1226+
return true;
1227+
}
12591228

1260-
return true;
1261-
}
1229+
const completed = completeValueCatchingErrors(
1230+
exeContext,
1231+
itemType,
1232+
fieldNodes,
1233+
info,
1234+
itemPath,
1235+
item,
1236+
asyncPayloadRecord,
1237+
);
12621238

1263-
completedResults.push(completedItem);
1264-
} catch (rawError) {
1265-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
1266-
const handledError = handleFieldError(error, itemType, errors);
1267-
filterSubsequentPayloads(exeContext, itemPath, asyncPayloadRecord);
1268-
completedResults.push(handledError);
1269-
}
1239+
completedResults.push(completed);
12701240

1271-
return false;
1241+
return isPromise(completed);
12721242
}
12731243

12741244
/**

0 commit comments

Comments
 (0)