@@ -1269,7 +1269,6 @@ async function completeAsyncIteratorValue(
1269
1269
break ;
1270
1270
}
1271
1271
1272
- const itemPath = addPath ( path , index , undefined ) ;
1273
1272
let iteration ;
1274
1273
try {
1275
1274
// eslint-disable-next-line no-await-in-loop
@@ -1288,44 +1287,19 @@ async function completeAsyncIteratorValue(
1288
1287
break ;
1289
1288
}
1290
1289
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
+
1329
1303
index ++ ;
1330
1304
}
1331
1305
} catch ( error ) {
@@ -1448,39 +1422,19 @@ function completeIterableValue(
1448
1422
1449
1423
// No need to modify the info object containing the path,
1450
1424
// 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
+ ) ;
1452
1437
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
- }
1484
1438
index ++ ;
1485
1439
1486
1440
iteration = iterator . next ( ) ;
@@ -1500,6 +1454,48 @@ function completeIterableValue(
1500
1454
*
1501
1455
* Returns true if the value is a Promise.
1502
1456
*/
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
+
1503
1499
function completeListItemValue (
1504
1500
item : unknown ,
1505
1501
completedResults : Array < unknown > ,
0 commit comments