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 20, 2024
1 parent cf4d620 commit ce9b4ab
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 ce9b4ab

Please sign in to comment.