From 9d956223616c053e53a6d64b8eca3379c7a13eeb Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Sun, 7 Apr 2024 12:38:16 +0300 Subject: [PATCH] refactor: introduce completeIterableValue simplifies function code, prelude to splitting functions into stream and non-stream versions --- 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;