From d811c97d57d14f579fc546b2f03f783f590c33bb Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Wed, 24 Apr 2024 19:35:28 +0300 Subject: [PATCH] refactor: introduce completeIterableValue (#4052) refactoring that will streamline when we introduce two versions of this function to optimize the loop when not streaming depends on #4051 --- src/execution/execute.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 42e3b9adf8..cda6ab8254 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -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, + incrementalContext: IncrementalContext | undefined, + deferMap: ReadonlyMap | undefined, +): PromiseOrValue>> { // 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; @@ -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;