Skip to content

Commit b872636

Browse files
committed
use completeListItemValue within completeAsyncIteratorValue
1 parent 8fa2b9f commit b872636

File tree

1 file changed

+20
-44
lines changed

1 file changed

+20
-44
lines changed

src/execution/execute.ts

Lines changed: 20 additions & 44 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,58 +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(
1031-
exeContext,
1032-
itemPath,
1033-
asyncPayloadRecord,
1034-
);
1035-
return handledError;
1036-
}),
1037-
);
1038-
} else {
1039-
completedResults.push(completedItem);
1040-
}
1041-
} catch (rawError) {
1042-
completedResults.push(null);
1043-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
1044-
filterSubsequentPayloads(exeContext, itemPath, asyncPayloadRecord);
1045-
handleFieldError(error, itemType, errors);
1046-
}
10471007
} catch (rawError) {
10481008
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
10491009
completedResults.push(handleFieldError(error, itemType, errors));
10501010
break;
10511011
}
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+
}
10521028
index += 1;
10531029
}
10541030
return containsPromise ? Promise.all(completedResults) : completedResults;

0 commit comments

Comments
 (0)