Skip to content

Commit d811c97

Browse files
authored
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
1 parent 6acf33f commit d811c97

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
@@ -1188,6 +1188,28 @@ function completeListValue(
11881188
);
11891189
}
11901190

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

0 commit comments

Comments
 (0)