Skip to content

Commit 84c243c

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

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
@@ -1182,6 +1182,28 @@ function completeListValue(
11821182
);
11831183
}
11841184

1185+
return completeIterableValue(
1186+
exeContext,
1187+
itemType,
1188+
fieldGroup,
1189+
info,
1190+
path,
1191+
result,
1192+
incrementalContext,
1193+
deferMap,
1194+
);
1195+
}
1196+
1197+
function completeIterableValue(
1198+
exeContext: ExecutionContext,
1199+
itemType: GraphQLOutputType,
1200+
fieldGroup: FieldGroup,
1201+
info: GraphQLResolveInfo,
1202+
path: Path,
1203+
items: Iterable<unknown>,
1204+
incrementalContext: IncrementalContext | undefined,
1205+
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
1206+
): PromiseOrValue<GraphQLWrappedResult<ReadonlyArray<unknown>>> {
11851207
// This is specified as a simple map, however we're optimizing the path
11861208
// where the list contains no Promises by avoiding creating another Promise.
11871209
let containsPromise = false;
@@ -1192,7 +1214,7 @@ function completeListValue(
11921214
];
11931215
let index = 0;
11941216
const streamUsage = getStreamUsage(exeContext, fieldGroup, path);
1195-
const iterator = result[Symbol.iterator]();
1217+
const iterator = items[Symbol.iterator]();
11961218
let iteration = iterator.next();
11971219
while (!iteration.done) {
11981220
const item = iteration.value;

0 commit comments

Comments
 (0)