Skip to content

Commit

Permalink
refactor: introduce completeIterableValue
Browse files Browse the repository at this point in the history
simplifies function code, prelude to splitting functions into stream and non-stream versions
  • Loading branch information
yaacovCR committed Apr 8, 2024
1 parent d171b67 commit 868f8ae
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,14 +1189,36 @@ function completeListValue(
);
}

return completeIterableValue(
exeContext,
itemType,
fieldGroup,
info,
path,
result,
incrementalContext,
deferMap,
);
}

function completeIterableValue(
exeContext: ExecutionContext,
itemType: GraphQLOutputType,
fieldGroup: FieldGroup,
info: GraphQLResolveInfo,
path: Path,
items: Iterable<unknown>,
incrementalContext: IncrementalContext | undefined,
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
): PromiseOrValue<GraphQLResult<ReadonlyArray<unknown>>> {
// This is specified as a simple map, however we're optimizing the path
// where the list contains no Promises by avoiding creating another Promise.
let containsPromise = false;
const completedResults: Array<unknown> = [];
const acc: GraphQLResult<Array<unknown>> = [completedResults, []];
let index = 0;
const streamUsage = getStreamUsage(exeContext, fieldGroup, path);
const iterator = result[Symbol.iterator]();
const iterator = items[Symbol.iterator]();
let iteration = iterator.next();
while (!iteration.done) {
const item = iteration.value;
Expand Down

0 comments on commit 868f8ae

Please sign in to comment.