Skip to content

Commit

Permalink
fix(stream): allow initialValue of zero
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Mar 22, 2021
1 parent 24330c0 commit e0e3cad
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,26 @@ function completeAsyncIteratorValue(
let containsPromise = false;
const stream = getStreamValues(exeContext, fieldNodes);
return new Promise((resolve) => {
function next(index, completedResults) {
function advance(index, completedResults) {
if (
stream &&
typeof stream.initialCount === 'number' &&
index >= stream.initialCount
) {
exeContext.dispatcher.addAsyncIteratorValue(
stream.label,
index,
path,
iterator,
exeContext,
fieldNodes,
info,
itemType,
);
resolve(completedResults);
return;
}

const fieldPath = addPath(path, index, undefined);
iterator.next().then(
({ value, done }) => {
Expand Down Expand Up @@ -1067,26 +1086,7 @@ function completeAsyncIteratorValue(
return;
}

const newIndex = index + 1;
if (
stream &&
typeof stream.initialCount === 'number' &&
newIndex >= stream.initialCount
) {
exeContext.dispatcher.addAsyncIteratorValue(
stream.label,
newIndex,
path,
iterator,
exeContext,
fieldNodes,
info,
itemType,
);
resolve(completedResults);
return;
}
next(newIndex, completedResults);
advance(index + 1, completedResults);
},
(rawError) => {
completedResults.push(null);
Expand All @@ -1100,7 +1100,7 @@ function completeAsyncIteratorValue(
},
);
}
next(0, []);
advance(0, []);
}).then((completedResults) =>
containsPromise ? Promise.all(completedResults) : completedResults,
);
Expand Down

0 comments on commit e0e3cad

Please sign in to comment.