Skip to content

Commit

Permalink
refactor: introduce completeIterableValue (#4052)
Browse files Browse the repository at this point in the history
refactoring that will streamline when we introduce two versions of this
function to optimize the loop when not streaming

depends on #4051
  • Loading branch information
yaacovCR authored Apr 24, 2024
1 parent 6acf33f commit d811c97
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 @@ -1188,6 +1188,28 @@ 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<GraphQLWrappedResult<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;
Expand All @@ -1198,7 +1220,7 @@ function completeListValue(
];
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 d811c97

Please sign in to comment.