@@ -707,16 +707,14 @@ function executeField(
707
707
708
708
result = resolveFn ( source , args , contextValue , info ) ;
709
709
} catch ( rawError ) {
710
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
711
- const handledError = addError (
710
+ handleRawError (
712
711
rawError ,
712
+ exeContext ,
713
713
fieldNodes ,
714
714
returnType ,
715
715
path ,
716
- errors ,
716
+ asyncPayloadRecord ,
717
717
) ;
718
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
719
- return handledError ;
720
718
}
721
719
722
720
if ( isPromise ( result ) ) {
@@ -751,32 +749,32 @@ function completePromiseCatchingErrors(
751
749
result : Promise < unknown > ,
752
750
asyncPayloadRecord ?: AsyncPayloadRecord ,
753
751
) : Promise < unknown > {
754
- return result
755
- . then ( ( resolved ) =>
756
- completeValue (
757
- exeContext ,
758
- returnType ,
759
- fieldNodes ,
760
- info ,
761
- path ,
762
- resolved ,
763
- asyncPayloadRecord ,
764
- ) ,
765
- )
766
- . then ( undefined , ( rawError ) => {
752
+ return (
753
+ result
754
+ . then ( ( resolved ) =>
755
+ completeValue (
756
+ exeContext ,
757
+ returnType ,
758
+ fieldNodes ,
759
+ info ,
760
+ path ,
761
+ resolved ,
762
+ asyncPayloadRecord ,
763
+ ) ,
764
+ )
767
765
// Note: we don't rely on a `catch` method, but we do expect "thenable"
768
766
// to take a second callback for the error case.
769
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
770
- const handledError = addError (
771
- rawError ,
772
- fieldNodes ,
773
- returnType ,
774
- path ,
775
- errors ,
776
- ) ;
777
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
778
- return handledError ;
779
- } ) ;
767
+ . then ( undefined , ( rawError ) =>
768
+ handleRawError (
769
+ rawError ,
770
+ exeContext ,
771
+ fieldNodes ,
772
+ returnType ,
773
+ path ,
774
+ asyncPayloadRecord ,
775
+ ) ,
776
+ )
777
+ ) ;
780
778
}
781
779
782
780
function completeValueCatchingErrors (
@@ -800,33 +798,29 @@ function completeValueCatchingErrors(
800
798
asyncPayloadRecord ,
801
799
) ;
802
800
} catch ( rawError ) {
803
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
804
- const handledError = addError (
801
+ return handleRawError (
805
802
rawError ,
803
+ exeContext ,
806
804
fieldNodes ,
807
805
returnType ,
808
806
path ,
809
- errors ,
807
+ asyncPayloadRecord ,
810
808
) ;
811
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
812
- return handledError ;
813
809
}
814
810
815
811
if ( isPromise ( completedItem ) ) {
816
812
// Note: we don't rely on a `catch` method, but we do expect "thenable"
817
813
// to take a second callback for the error case.
818
- completedItem = completedItem . then ( undefined , ( rawError ) => {
819
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
820
- const handledError = addError (
814
+ completedItem = completedItem . then ( undefined , ( rawError ) =>
815
+ handleRawError (
821
816
rawError ,
817
+ exeContext ,
822
818
fieldNodes ,
823
819
returnType ,
824
820
path ,
825
- errors ,
826
- ) ;
827
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
828
- return handledError ;
829
- } ) ;
821
+ asyncPayloadRecord ,
822
+ ) ,
823
+ ) ;
830
824
}
831
825
return completedItem ;
832
826
}
@@ -858,6 +852,20 @@ export function buildResolveInfo(
858
852
} ;
859
853
}
860
854
855
+ function handleRawError (
856
+ rawError : unknown ,
857
+ exeContext : ExecutionContext ,
858
+ fieldNodes : ReadonlyArray < FieldNode > ,
859
+ returnType : GraphQLOutputType ,
860
+ path : Path ,
861
+ asyncPayloadRecord : AsyncPayloadRecord | undefined ,
862
+ ) : null {
863
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
864
+ addError ( rawError , fieldNodes , returnType , path , errors ) ;
865
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
866
+ return null ;
867
+ }
868
+
861
869
function addError (
862
870
rawError : unknown ,
863
871
fieldNodes : ReadonlyArray < FieldNode > ,
0 commit comments