Skip to content

Commit 868f8ae

Browse files
committed
refactor: introduce completeIterableValue
simplifies function code, prelude to splitting functions into stream and non-stream versions
1 parent d171b67 commit 868f8ae

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/execution/execute.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,36 @@ function completeListValue(
11891189
);
11901190
}
11911191

1192+
return completeIterableValue(
1193+
exeContext,
1194+
itemType,
1195+
fieldGroup,
1196+
info,
1197+
path,
1198+
result,
1199+
incrementalContext,
1200+
deferMap,
1201+
);
1202+
}
1203+
1204+
function completeIterableValue(
1205+
exeContext: ExecutionContext,
1206+
itemType: GraphQLOutputType,
1207+
fieldGroup: FieldGroup,
1208+
info: GraphQLResolveInfo,
1209+
path: Path,
1210+
items: Iterable<unknown>,
1211+
incrementalContext: IncrementalContext | undefined,
1212+
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
1213+
): PromiseOrValue<GraphQLResult<ReadonlyArray<unknown>>> {
11921214
// This is specified as a simple map, however we're optimizing the path
11931215
// where the list contains no Promises by avoiding creating another Promise.
11941216
let containsPromise = false;
11951217
const completedResults: Array<unknown> = [];
11961218
const acc: GraphQLResult<Array<unknown>> = [completedResults, []];
11971219
let index = 0;
11981220
const streamUsage = getStreamUsage(exeContext, fieldGroup, path);
1199-
const iterator = result[Symbol.iterator]();
1221+
const iterator = items[Symbol.iterator]();
12001222
let iteration = iterator.next();
12011223
while (!iteration.done) {
12021224
const item = iteration.value;

0 commit comments

Comments
 (0)