Skip to content

Commit c9ed12c

Browse files
committed
introduce completeMaybePromisedListItemValue
1 parent 12a5ec9 commit c9ed12c

File tree

1 file changed

+69
-68
lines changed

1 file changed

+69
-68
lines changed

src/execution/execute.ts

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,43 +1273,20 @@ async function completeAsyncIteratorValue(
12731273
}
12741274

12751275
const item = iteration.value;
1276-
// TODO: add tests for stream backed by asyncIterator that returns a promise
1277-
/* c8 ignore start */
1278-
if (isPromise(item)) {
1279-
completedResults.push(
1280-
completePromisedListItemValue(
1281-
item,
1282-
graphqlWrappedResult,
1283-
exeContext,
1284-
itemType,
1285-
fieldDetailsList,
1286-
info,
1287-
itemPath,
1288-
incrementalContext,
1289-
deferMap,
1290-
),
1291-
);
1292-
containsPromise = true;
1293-
} else if (
1294-
/* c8 ignore stop */
1295-
completeListItemValue(
1296-
item,
1297-
completedResults,
1298-
graphqlWrappedResult,
1299-
exeContext,
1300-
itemType,
1301-
fieldDetailsList,
1302-
info,
1303-
itemPath,
1304-
incrementalContext,
1305-
deferMap,
1306-
)
1307-
// TODO: add tests for stream backed by asyncIterator that completes to a promise
1308-
/* c8 ignore start */
1309-
) {
1310-
containsPromise = true;
1311-
}
1312-
/* c8 ignore stop */
1276+
1277+
containsPromise = completeMaybePromisedListItemValue(
1278+
item,
1279+
completedResults,
1280+
graphqlWrappedResult,
1281+
exeContext,
1282+
itemType,
1283+
fieldDetailsList,
1284+
info,
1285+
itemPath,
1286+
incrementalContext,
1287+
deferMap,
1288+
);
1289+
13131290
index++;
13141291
}
13151292
} catch (error) {
@@ -1432,37 +1409,19 @@ function completeIterableValue(
14321409
// since from here on it is not ever accessed by resolver functions.
14331410
const itemPath = addPath(path, index, undefined);
14341411

1435-
if (isPromise(item)) {
1436-
completedResults.push(
1437-
completePromisedListItemValue(
1438-
item,
1439-
graphqlWrappedResult,
1440-
exeContext,
1441-
itemType,
1442-
fieldDetailsList,
1443-
info,
1444-
itemPath,
1445-
incrementalContext,
1446-
deferMap,
1447-
),
1448-
);
1449-
containsPromise = true;
1450-
} else if (
1451-
completeListItemValue(
1452-
item,
1453-
completedResults,
1454-
graphqlWrappedResult,
1455-
exeContext,
1456-
itemType,
1457-
fieldDetailsList,
1458-
info,
1459-
itemPath,
1460-
incrementalContext,
1461-
deferMap,
1462-
)
1463-
) {
1464-
containsPromise = true;
1465-
}
1412+
containsPromise = completeMaybePromisedListItemValue(
1413+
item,
1414+
completedResults,
1415+
graphqlWrappedResult,
1416+
exeContext,
1417+
itemType,
1418+
fieldDetailsList,
1419+
info,
1420+
itemPath,
1421+
incrementalContext,
1422+
deferMap,
1423+
);
1424+
14661425
index++;
14671426

14681427
iteration = iterator.next();
@@ -1481,6 +1440,48 @@ function completeIterableValue(
14811440
*
14821441
* Returns true if the value is a Promise.
14831442
*/
1443+
function completeMaybePromisedListItemValue(
1444+
item: unknown,
1445+
completedResults: Array<unknown>,
1446+
parent: GraphQLWrappedResult<Array<unknown>>,
1447+
exeContext: ExecutionContext,
1448+
itemType: GraphQLOutputType,
1449+
fieldDetailsList: FieldDetailsList,
1450+
info: GraphQLResolveInfo,
1451+
itemPath: Path,
1452+
incrementalContext: IncrementalContext | undefined,
1453+
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
1454+
): boolean {
1455+
if (isPromise(item)) {
1456+
completedResults.push(
1457+
completePromisedListItemValue(
1458+
item,
1459+
parent,
1460+
exeContext,
1461+
itemType,
1462+
fieldDetailsList,
1463+
info,
1464+
itemPath,
1465+
incrementalContext,
1466+
deferMap,
1467+
),
1468+
);
1469+
return true;
1470+
}
1471+
return completeListItemValue(
1472+
item,
1473+
completedResults,
1474+
parent,
1475+
exeContext,
1476+
itemType,
1477+
fieldDetailsList,
1478+
info,
1479+
itemPath,
1480+
incrementalContext,
1481+
deferMap,
1482+
);
1483+
}
1484+
14841485
function completeListItemValue(
14851486
item: unknown,
14861487
completedResults: Array<unknown>,

0 commit comments

Comments
 (0)