@@ -748,15 +748,33 @@ function executeField(
748
748
const result = resolveFn ( source , args , contextValue , info ) ;
749
749
750
750
if ( isPromise ( result ) ) {
751
- return completePromisedValue (
752
- exeContext ,
753
- returnType ,
754
- fieldGroup ,
755
- info ,
756
- path ,
757
- result ,
758
- incrementalContext ,
759
- deferMap ,
751
+ return (
752
+ result
753
+ . then ( ( resolved ) =>
754
+ completeValue (
755
+ exeContext ,
756
+ returnType ,
757
+ fieldGroup ,
758
+ info ,
759
+ path ,
760
+ resolved ,
761
+ incrementalContext ,
762
+ deferMap ,
763
+ ) ,
764
+ )
765
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
766
+ // to take a second callback for the error case.
767
+ . then ( undefined , ( rawError ) => {
768
+ handleFieldError (
769
+ rawError ,
770
+ exeContext ,
771
+ returnType ,
772
+ fieldGroup ,
773
+ path ,
774
+ incrementalContext ,
775
+ ) ;
776
+ return null ;
777
+ } )
760
778
) ;
761
779
}
762
780
@@ -972,46 +990,6 @@ function completeValue(
972
990
) ;
973
991
}
974
992
975
- async function completePromisedValue (
976
- exeContext : ExecutionContext ,
977
- returnType : GraphQLOutputType ,
978
- fieldGroup : FieldGroup ,
979
- info : GraphQLResolveInfo ,
980
- path : Path ,
981
- result : Promise < unknown > ,
982
- incrementalContext : IncrementalContext | undefined ,
983
- deferMap : ReadonlyMap < DeferUsage , DeferredFragmentRecord > | undefined ,
984
- ) : Promise < unknown > {
985
- try {
986
- const resolved = await result ;
987
- let completed = completeValue (
988
- exeContext ,
989
- returnType ,
990
- fieldGroup ,
991
- info ,
992
- path ,
993
- resolved ,
994
- incrementalContext ,
995
- deferMap ,
996
- ) ;
997
-
998
- if ( isPromise ( completed ) ) {
999
- completed = await completed ;
1000
- }
1001
- return completed ;
1002
- } catch ( rawError ) {
1003
- handleFieldError (
1004
- rawError ,
1005
- exeContext ,
1006
- returnType ,
1007
- fieldGroup ,
1008
- path ,
1009
- incrementalContext ,
1010
- ) ;
1011
- return null ;
1012
- }
1013
- }
1014
-
1015
993
/**
1016
994
* Returns an object containing info for streaming if a field should be
1017
995
* streamed based on the experimental flag, stream directive present and
@@ -1452,16 +1430,32 @@ function completeListItemValue(
1452
1430
) : boolean {
1453
1431
if ( isPromise ( item ) ) {
1454
1432
completedResults . push (
1455
- completePromisedValue (
1456
- exeContext ,
1457
- itemType ,
1458
- fieldGroup ,
1459
- info ,
1460
- itemPath ,
1461
- item ,
1462
- incrementalContext ,
1463
- deferMap ,
1464
- ) ,
1433
+ item
1434
+ . then ( ( resolved ) =>
1435
+ completeValue (
1436
+ exeContext ,
1437
+ itemType ,
1438
+ fieldGroup ,
1439
+ info ,
1440
+ itemPath ,
1441
+ resolved ,
1442
+ incrementalContext ,
1443
+ deferMap ,
1444
+ ) ,
1445
+ )
1446
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
1447
+ // to take a second callback for the error case.
1448
+ . then ( undefined , ( rawError ) => {
1449
+ handleFieldError (
1450
+ rawError ,
1451
+ exeContext ,
1452
+ itemType ,
1453
+ fieldGroup ,
1454
+ itemPath ,
1455
+ incrementalContext ,
1456
+ ) ;
1457
+ return null ;
1458
+ } ) ,
1465
1459
) ;
1466
1460
return true ;
1467
1461
}
@@ -2488,24 +2482,43 @@ function completeStreamItems(
2488
2482
itemType : GraphQLOutputType ,
2489
2483
) : PromiseOrValue < StreamItemsResult > {
2490
2484
if ( isPromise ( item ) ) {
2491
- return completePromisedValue (
2492
- exeContext ,
2493
- itemType ,
2494
- fieldGroup ,
2495
- info ,
2496
- itemPath ,
2497
- item ,
2498
- incrementalContext ,
2499
- new Map ( ) ,
2500
- ) . then (
2501
- ( resolvedItem ) =>
2502
- buildStreamItemsResult ( incrementalContext , streamRecord , resolvedItem ) ,
2503
- ( error ) => ( {
2504
- streamRecord,
2505
- result : null ,
2506
- errors : withError ( incrementalContext . errors , error ) ,
2507
- } ) ,
2508
- ) ;
2485
+ return item
2486
+ . then ( ( resolved ) =>
2487
+ completeValue (
2488
+ exeContext ,
2489
+ itemType ,
2490
+ fieldGroup ,
2491
+ info ,
2492
+ itemPath ,
2493
+ resolved ,
2494
+ incrementalContext ,
2495
+ new Map ( ) ,
2496
+ ) ,
2497
+ )
2498
+ . then ( undefined , ( rawError ) => {
2499
+ handleFieldError (
2500
+ rawError ,
2501
+ exeContext ,
2502
+ itemType ,
2503
+ fieldGroup ,
2504
+ itemPath ,
2505
+ incrementalContext ,
2506
+ ) ;
2507
+ return null ;
2508
+ } )
2509
+ . then (
2510
+ ( resolvedItem ) =>
2511
+ buildStreamItemsResult (
2512
+ incrementalContext ,
2513
+ streamRecord ,
2514
+ resolvedItem ,
2515
+ ) ,
2516
+ ( error ) => ( {
2517
+ streamRecord,
2518
+ result : null ,
2519
+ errors : withError ( incrementalContext . errors , error ) ,
2520
+ } ) ,
2521
+ ) ;
2509
2522
}
2510
2523
2511
2524
let completedItem ;
0 commit comments