Skip to content

Commit 0afaedc

Browse files
committed
use completeListItemValue within completeAsyncIteratorValue
1 parent e0cc0e7 commit 0afaedc

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

src/execution/execute.ts

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ async function completeAsyncIteratorValue(
972972
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
973973
const stream = getStreamValues(exeContext, fieldNodes, path);
974974
let containsPromise = false;
975-
const completedResults = [];
975+
const completedResults: Array<unknown> = [];
976976
let index = 0;
977977
// eslint-disable-next-line no-constant-condition
978978
while (true) {
@@ -997,54 +997,34 @@ async function completeAsyncIteratorValue(
997997
}
998998

999999
const itemPath = addPath(path, index, undefined);
1000+
let iteration;
10001001
try {
10011002
// eslint-disable-next-line no-await-in-loop
1002-
const { value, done } = await iterator.next();
1003-
if (done) {
1003+
iteration = await iterator.next();
1004+
if (iteration.done) {
10041005
break;
10051006
}
1006-
1007-
try {
1008-
// TODO can the error checking logic be consolidated with completeListValue?
1009-
const completedItem = completeValue(
1010-
exeContext,
1011-
itemType,
1012-
fieldNodes,
1013-
info,
1014-
itemPath,
1015-
value,
1016-
asyncPayloadRecord,
1017-
);
1018-
if (isPromise(completedItem)) {
1019-
containsPromise = true;
1020-
// Note: we don't rely on a `catch` method, but we do expect "thenable"
1021-
// to take a second callback for the error case.
1022-
completedResults.push(
1023-
completedItem.then(undefined, (rawError) => {
1024-
const error = locatedError(
1025-
rawError,
1026-
fieldNodes,
1027-
pathToArray(itemPath),
1028-
);
1029-
const handledError = handleFieldError(error, itemType, errors);
1030-
filterSubsequentPayloads(exeContext, itemPath);
1031-
return handledError;
1032-
}),
1033-
);
1034-
} else {
1035-
completedResults.push(completedItem);
1036-
}
1037-
} catch (rawError) {
1038-
completedResults.push(null);
1039-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
1040-
filterSubsequentPayloads(exeContext, itemPath);
1041-
handleFieldError(error, itemType, errors);
1042-
}
10431007
} catch (rawError) {
10441008
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
10451009
completedResults.push(handleFieldError(error, itemType, errors));
10461010
break;
10471011
}
1012+
1013+
if (
1014+
completeListItemValue(
1015+
iteration.value,
1016+
completedResults,
1017+
errors,
1018+
exeContext,
1019+
itemType,
1020+
fieldNodes,
1021+
info,
1022+
itemPath,
1023+
asyncPayloadRecord,
1024+
)
1025+
) {
1026+
containsPromise = true;
1027+
}
10481028
index += 1;
10491029
}
10501030
return containsPromise ? Promise.all(completedResults) : completedResults;

0 commit comments

Comments
 (0)