From 868f8ae186c1c96b95f78a6c204a51771662b301 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 8a97b5e52cb..a7fff0484f5 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -1189,6 +1189,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; @@ -1196,7 +1218,7 @@ function completeListValue( const acc: GraphQLResult> = [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;