Skip to content

Commit 05153dc

Browse files
committed
isolate async iterator next rejection within try block
to improve readability
1 parent c7f5b5f commit 05153dc

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/execution/execute.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,15 +1065,16 @@ async function completeAsyncIteratorValue(
10651065
try {
10661066
// eslint-disable-next-line no-await-in-loop
10671067
iteration = await iterator.next();
1068-
if (iteration.done) {
1069-
break;
1070-
}
10711068
} catch (rawError) {
10721069
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
10731070
completedResults.push(handleFieldError(error, itemType, errors));
10741071
break;
10751072
}
10761073

1074+
if (iteration.done) {
1075+
break;
1076+
}
1077+
10771078
if (
10781079
completeListItemValue(
10791080
iteration.value,
@@ -2008,30 +2009,34 @@ async function executeStreamAsyncIteratorItem(
20082009
asyncPayloadRecord: StreamItemRecord,
20092010
itemPath: Path,
20102011
): Promise<IteratorResult<unknown>> {
2012+
let iteration;
20112013
try {
2012-
const { value, done } = await iterator.next();
2013-
if (done) {
2014-
asyncPayloadRecord.setIsCompletedIterator();
2015-
return { done, value: undefined };
2016-
}
2017-
return {
2018-
done: false,
2019-
value: completeValueCatchingErrors(
2020-
exeContext,
2021-
itemType,
2022-
fieldNodes,
2023-
info,
2024-
itemPath,
2025-
value,
2026-
asyncPayloadRecord,
2027-
),
2028-
};
2014+
iteration = await iterator.next();
20292015
} catch (rawError) {
20302016
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
20312017
const value = handleFieldError(error, itemType, asyncPayloadRecord.errors);
20322018
// don't continue if iterator throws
20332019
return { done: true, value };
20342020
}
2021+
2022+
const { value, done } = iteration;
2023+
2024+
if (done) {
2025+
asyncPayloadRecord.setIsCompletedIterator();
2026+
return { done, value: undefined };
2027+
}
2028+
return {
2029+
done: false,
2030+
value: completeValueCatchingErrors(
2031+
exeContext,
2032+
itemType,
2033+
fieldNodes,
2034+
info,
2035+
itemPath,
2036+
value,
2037+
asyncPayloadRecord,
2038+
),
2039+
};
20352040
}
20362041

20372042
async function executeStreamAsyncIterator(

0 commit comments

Comments
 (0)