Skip to content

Commit 4cf7098

Browse files
committed
change execute implementation for async iterable resolvers
# Conflicts: # src/execution/execute.js
1 parent 749b77c commit 4cf7098

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

src/execution/execute.js

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -867,37 +867,57 @@ function completeAsyncIteratorValue(
867867
fieldNodes: $ReadOnlyArray<FieldNode>,
868868
info: GraphQLResolveInfo,
869869
path: Path,
870-
index: number,
871-
completedResults: Array<mixed>,
872870
iterator: AsyncIterator<mixed>,
873871
): Promise<$ReadOnlyArray<mixed>> {
874-
const fieldPath = addPath(path, index, undefined);
875-
return iterator.next().then(
876-
({ value, done }) => {
877-
if (done) {
878-
return completedResults;
879-
}
880-
completedResults.push(
881-
completeValue(exeContext, itemType, fieldNodes, info, fieldPath, value),
882-
);
883-
return completeAsyncIteratorValue(
884-
exeContext,
885-
itemType,
886-
fieldNodes,
887-
info,
888-
path,
889-
index + 1,
890-
completedResults,
891-
iterator,
872+
return new Promise((resolve) => {
873+
function next(index, completedResults) {
874+
const fieldPath = addPath(path, index, undefined);
875+
iterator.next().then(
876+
({ value, done }) => {
877+
if (done) {
878+
resolve(completedResults);
879+
return;
880+
}
881+
// TODO can the error checking logic be consolidated with completeListValue?
882+
try {
883+
completedResults.push(
884+
completeValue(
885+
exeContext,
886+
itemType,
887+
fieldNodes,
888+
info,
889+
fieldPath,
890+
value,
891+
),
892+
);
893+
} catch (rawError) {
894+
completedResults.push(null);
895+
const error = locatedError(
896+
rawError,
897+
fieldNodes,
898+
pathToArray(fieldPath),
899+
);
900+
handleFieldError(error, itemType, exeContext);
901+
resolve(completedResults);
902+
return;
903+
}
904+
905+
next(index + 1, completedResults);
906+
},
907+
(rawError) => {
908+
completedResults.push(null);
909+
const error = locatedError(
910+
rawError,
911+
fieldNodes,
912+
pathToArray(fieldPath),
913+
);
914+
handleFieldError(error, itemType, exeContext);
915+
resolve(completedResults);
916+
},
892917
);
893-
},
894-
(rawError) => {
895-
completedResults.push(null);
896-
const error = locatedError(rawError, fieldNodes, pathToArray(fieldPath));
897-
handleFieldError(error, itemType, exeContext);
898-
return completedResults;
899-
},
900-
);
918+
}
919+
next(0, []);
920+
});
901921
}
902922

903923
/**
@@ -923,8 +943,6 @@ function completeListValue(
923943
fieldNodes,
924944
info,
925945
path,
926-
0,
927-
[],
928946
iterator,
929947
);
930948
}

0 commit comments

Comments
 (0)