Skip to content

Commit c16d429

Browse files
committed
introduce completeMaybePromisedListItemValue
1 parent 6a913ce commit c16d429

File tree

1 file changed

+67
-71
lines changed

1 file changed

+67
-71
lines changed

src/execution/execute.ts

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,6 @@ async function completeAsyncIteratorValue(
12691269
break;
12701270
}
12711271

1272-
const itemPath = addPath(path, index, undefined);
12731272
let iteration;
12741273
try {
12751274
// eslint-disable-next-line no-await-in-loop
@@ -1288,44 +1287,19 @@ async function completeAsyncIteratorValue(
12881287
break;
12891288
}
12901289

1291-
const item = iteration.value;
1292-
// TODO: add tests for stream backed by asyncIterator that returns a promise
1293-
/* c8 ignore start */
1294-
if (isPromise(item)) {
1295-
completedResults.push(
1296-
completePromisedListItemValue(
1297-
item,
1298-
graphqlWrappedResult,
1299-
exeContext,
1300-
itemType,
1301-
fieldDetailsList,
1302-
info,
1303-
itemPath,
1304-
incrementalContext,
1305-
deferMap,
1306-
),
1307-
);
1308-
containsPromise = true;
1309-
} else if (
1310-
/* c8 ignore stop */
1311-
completeListItemValue(
1312-
item,
1313-
completedResults,
1314-
graphqlWrappedResult,
1315-
exeContext,
1316-
itemType,
1317-
fieldDetailsList,
1318-
info,
1319-
itemPath,
1320-
incrementalContext,
1321-
deferMap,
1322-
)
1323-
// TODO: add tests for stream backed by asyncIterator that completes to a promise
1324-
/* c8 ignore start */
1325-
) {
1326-
containsPromise = true;
1327-
}
1328-
/* c8 ignore stop */
1290+
containsPromise = completeMaybePromisedListItemValue(
1291+
iteration.value,
1292+
completedResults,
1293+
graphqlWrappedResult,
1294+
exeContext,
1295+
itemType,
1296+
fieldDetailsList,
1297+
info,
1298+
addPath(path, index, undefined),
1299+
incrementalContext,
1300+
deferMap,
1301+
);
1302+
13291303
index++;
13301304
}
13311305
} catch (error) {
@@ -1448,39 +1422,19 @@ function completeIterableValue(
14481422

14491423
// No need to modify the info object containing the path,
14501424
// since from here on it is not ever accessed by resolver functions.
1451-
const itemPath = addPath(path, index, undefined);
1425+
containsPromise = completeMaybePromisedListItemValue(
1426+
item,
1427+
completedResults,
1428+
graphqlWrappedResult,
1429+
exeContext,
1430+
itemType,
1431+
fieldDetailsList,
1432+
info,
1433+
addPath(path, index, undefined),
1434+
incrementalContext,
1435+
deferMap,
1436+
);
14521437

1453-
if (isPromise(item)) {
1454-
completedResults.push(
1455-
completePromisedListItemValue(
1456-
item,
1457-
graphqlWrappedResult,
1458-
exeContext,
1459-
itemType,
1460-
fieldDetailsList,
1461-
info,
1462-
itemPath,
1463-
incrementalContext,
1464-
deferMap,
1465-
),
1466-
);
1467-
containsPromise = true;
1468-
} else if (
1469-
completeListItemValue(
1470-
item,
1471-
completedResults,
1472-
graphqlWrappedResult,
1473-
exeContext,
1474-
itemType,
1475-
fieldDetailsList,
1476-
info,
1477-
itemPath,
1478-
incrementalContext,
1479-
deferMap,
1480-
)
1481-
) {
1482-
containsPromise = true;
1483-
}
14841438
index++;
14851439

14861440
iteration = iterator.next();
@@ -1500,6 +1454,48 @@ function completeIterableValue(
15001454
*
15011455
* Returns true if the value is a Promise.
15021456
*/
1457+
function completeMaybePromisedListItemValue(
1458+
item: unknown,
1459+
completedResults: Array<unknown>,
1460+
parent: GraphQLWrappedResult<Array<unknown>>,
1461+
exeContext: ExecutionContext,
1462+
itemType: GraphQLOutputType,
1463+
fieldDetailsList: FieldDetailsList,
1464+
info: GraphQLResolveInfo,
1465+
itemPath: Path,
1466+
incrementalContext: IncrementalContext | undefined,
1467+
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
1468+
): boolean {
1469+
if (isPromise(item)) {
1470+
completedResults.push(
1471+
completePromisedListItemValue(
1472+
item,
1473+
parent,
1474+
exeContext,
1475+
itemType,
1476+
fieldDetailsList,
1477+
info,
1478+
itemPath,
1479+
incrementalContext,
1480+
deferMap,
1481+
),
1482+
);
1483+
return true;
1484+
}
1485+
return completeListItemValue(
1486+
item,
1487+
completedResults,
1488+
parent,
1489+
exeContext,
1490+
itemType,
1491+
fieldDetailsList,
1492+
info,
1493+
itemPath,
1494+
incrementalContext,
1495+
deferMap,
1496+
);
1497+
}
1498+
15031499
function completeListItemValue(
15041500
item: unknown,
15051501
completedResults: Array<unknown>,

0 commit comments

Comments
 (0)