MCPcopy Create free account
hub / github.com/ardatan/graphql-tools / executeStreamIterator

Function executeStreamIterator

packages/executor/src/execution/execute.ts:2088–2159  ·  view source on GitHub ↗
(
  initialIndex: number,
  iterator: AsyncIterator<unknown>,
  exeContext: ExecutionContext,
  fieldNodes: Array<FieldNode>,
  info: GraphQLResolveInfo,
  itemType: GraphQLOutputType,
  path: Path,
  label?: string,
  parentContext?: AsyncPayloadRecord,
)

Source from the content-addressed store, hash-verified

2086}
2087
2088async function executeStreamIterator(
2089 initialIndex: number,
2090 iterator: AsyncIterator<unknown>,
2091 exeContext: ExecutionContext,
2092 fieldNodes: Array<FieldNode>,
2093 info: GraphQLResolveInfo,
2094 itemType: GraphQLOutputType,
2095 path: Path,
2096 label?: string,
2097 parentContext?: AsyncPayloadRecord,
2098): Promise<void> {
2099 let index = initialIndex;
2100 let previousAsyncPayloadRecord = parentContext ?? undefined;
2101 while (true) {
2102 const itemPath = addPath(path, index, undefined);
2103 const asyncPayloadRecord = new StreamRecord({
2104 label,
2105 path: itemPath,
2106 parentContext: previousAsyncPayloadRecord,
2107 iterator,
2108 exeContext,
2109 });
2110
2111 let iteration;
2112 try {
2113 iteration = await executeStreamIteratorItem(
2114 iterator,
2115 exeContext,
2116 fieldNodes,
2117 info,
2118 itemType,
2119 asyncPayloadRecord,
2120 itemPath,
2121 );
2122 } catch (error) {
2123 asyncPayloadRecord.errors.push(error as GraphQLError);
2124 filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
2125 asyncPayloadRecord.addItems(null);
2126 // entire stream has errored and bubbled upwards
2127 if (iterator?.return) {
2128 iterator.return().catch(() => {
2129 // ignore errors
2130 });
2131 }
2132 return;
2133 }
2134
2135 const { done, value: completedItem } = iteration;
2136
2137 let completedItems: MaybePromise<Array<unknown> | null>;
2138 if (isPromise(completedItem)) {
2139 completedItems = completedItem.then(
2140 value => [value],
2141 error => {
2142 asyncPayloadRecord.errors.push(error);
2143 filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
2144 return null;
2145 },

Callers 1

Calls 5

addItemsMethod · 0.95
addPathFunction · 0.90
filterSubsequentPayloadsFunction · 0.85
returnMethod · 0.80

Tested by

no test coverage detected