Skip to content

Commit 09181f2

Browse files
committed
use complete helpers within completeListItemValue
1 parent ece5007 commit 09181f2

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
@@ -1095,7 +1095,6 @@ async function completeAsyncIteratorValue(
10951095
completeListItemValue(
10961096
iteration.value,
10971097
completedResults,
1098-
errors,
10991098
exeContext,
11001099
itemType,
11011100
fieldNodes,
@@ -1125,7 +1124,6 @@ function completeListValue(
11251124
asyncPayloadRecord?: AsyncPayloadRecord,
11261125
): PromiseOrValue<ReadonlyArray<unknown>> {
11271126
const itemType = returnType.ofType;
1128-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
11291127

11301128
if (isAsyncIterable(result)) {
11311129
const iterator = result[Symbol.asyncIterator]();
@@ -1189,7 +1187,6 @@ function completeListValue(
11891187
completeListItemValue(
11901188
item,
11911189
completedResults,
1192-
errors,
11931190
exeContext,
11941191
itemType,
11951192
fieldNodes,
@@ -1215,68 +1212,41 @@ function completeListValue(
12151212
function completeListItemValue(
12161213
item: unknown,
12171214
completedResults: Array<unknown>,
1218-
errors: Array<GraphQLError>,
12191215
exeContext: ExecutionContext,
12201216
itemType: GraphQLOutputType,
12211217
fieldNodes: ReadonlyArray<FieldNode>,
12221218
info: GraphQLResolveInfo,
12231219
itemPath: Path,
12241220
asyncPayloadRecord?: AsyncPayloadRecord,
12251221
): boolean {
1226-
try {
1227-
let completedItem;
1228-
if (isPromise(item)) {
1229-
completedItem = item.then((resolved) =>
1230-
completeValue(
1231-
exeContext,
1232-
itemType,
1233-
fieldNodes,
1234-
info,
1235-
itemPath,
1236-
resolved,
1237-
asyncPayloadRecord,
1238-
),
1239-
);
1240-
} else {
1241-
completedItem = completeValue(
1222+
if (isPromise(item)) {
1223+
completedResults.push(
1224+
completePromiseCatchingErrors(
12421225
exeContext,
12431226
itemType,
12441227
fieldNodes,
12451228
info,
12461229
itemPath,
12471230
item,
12481231
asyncPayloadRecord,
1249-
);
1250-
}
1251-
1252-
if (isPromise(completedItem)) {
1253-
// Note: we don't rely on a `catch` method, but we do expect "thenable"
1254-
// to take a second callback for the error case.
1255-
completedResults.push(
1256-
completedItem.then(undefined, (rawError) => {
1257-
const error = locatedError(
1258-
rawError,
1259-
fieldNodes,
1260-
pathToArray(itemPath),
1261-
);
1262-
const handledError = handleFieldError(error, itemType, errors);
1263-
filterSubsequentPayloads(exeContext, itemPath, asyncPayloadRecord);
1264-
return handledError;
1265-
}),
1266-
);
1232+
),
1233+
);
1234+
return true;
1235+
}
12671236

1268-
return true;
1269-
}
1237+
const completed = completeValueCatchingErrors(
1238+
exeContext,
1239+
itemType,
1240+
fieldNodes,
1241+
info,
1242+
itemPath,
1243+
item,
1244+
asyncPayloadRecord,
1245+
);
12701246

1271-
completedResults.push(completedItem);
1272-
} catch (rawError) {
1273-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
1274-
const handledError = handleFieldError(error, itemType, errors);
1275-
filterSubsequentPayloads(exeContext, itemPath, asyncPayloadRecord);
1276-
completedResults.push(handledError);
1277-
}
1247+
completedResults.push(completed);
12781248

1279-
return false;
1249+
return isPromise(completed);
12801250
}
12811251

12821252
/**

0 commit comments

Comments
 (0)