@@ -708,8 +708,13 @@ function executeField(
708
708
result = resolveFn ( source , args , contextValue , info ) ;
709
709
} catch ( rawError ) {
710
710
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
711
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
712
- const handledError = handleFieldError ( error , returnType , errors ) ;
711
+ const handledError = addError (
712
+ rawError ,
713
+ fieldNodes ,
714
+ returnType ,
715
+ path ,
716
+ errors ,
717
+ ) ;
713
718
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
714
719
return handledError ;
715
720
}
@@ -762,8 +767,13 @@ function completePromiseCatchingErrors(
762
767
// Note: we don't rely on a `catch` method, but we do expect "thenable"
763
768
// to take a second callback for the error case.
764
769
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
765
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
766
- const handledError = handleFieldError ( error , returnType , errors ) ;
770
+ const handledError = addError (
771
+ rawError ,
772
+ fieldNodes ,
773
+ returnType ,
774
+ path ,
775
+ errors ,
776
+ ) ;
767
777
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
768
778
return handledError ;
769
779
} ) ;
@@ -791,8 +801,13 @@ function completeValueCatchingErrors(
791
801
) ;
792
802
} catch ( rawError ) {
793
803
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
794
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
795
- const handledError = handleFieldError ( error , returnType , errors ) ;
804
+ const handledError = addError (
805
+ rawError ,
806
+ fieldNodes ,
807
+ returnType ,
808
+ path ,
809
+ errors ,
810
+ ) ;
796
811
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
797
812
return handledError ;
798
813
}
@@ -802,8 +817,13 @@ function completeValueCatchingErrors(
802
817
// to take a second callback for the error case.
803
818
completedItem = completedItem . then ( undefined , ( rawError ) => {
804
819
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
805
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
806
- const handledError = handleFieldError ( error , returnType , errors ) ;
820
+ const handledError = addError (
821
+ rawError ,
822
+ fieldNodes ,
823
+ returnType ,
824
+ path ,
825
+ errors ,
826
+ ) ;
807
827
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
808
828
return handledError ;
809
829
} ) ;
@@ -838,11 +858,15 @@ export function buildResolveInfo(
838
858
} ;
839
859
}
840
860
841
- function handleFieldError (
842
- error : GraphQLError ,
861
+ function addError (
862
+ rawError : unknown ,
863
+ fieldNodes : ReadonlyArray < FieldNode > ,
843
864
returnType : GraphQLOutputType ,
865
+ path : Path ,
844
866
errors : Array < GraphQLError > ,
845
867
) : null {
868
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
869
+
846
870
// If the field type is non-nullable, then it is resolved without any
847
871
// protection from errors, however it still properly locates the error.
848
872
if ( isNonNullType ( returnType ) ) {
@@ -1066,8 +1090,9 @@ async function completeAsyncIteratorValue(
1066
1090
// eslint-disable-next-line no-await-in-loop
1067
1091
iteration = await iterator . next ( ) ;
1068
1092
} catch ( rawError ) {
1069
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1070
- completedResults . push ( handleFieldError ( error , itemType , errors ) ) ;
1093
+ completedResults . push (
1094
+ addError ( rawError , fieldNodes , itemType , itemPath , errors ) ,
1095
+ ) ;
1071
1096
break ;
1072
1097
}
1073
1098
@@ -2013,8 +2038,13 @@ async function executeStreamAsyncIteratorItem(
2013
2038
try {
2014
2039
iteration = await iterator . next ( ) ;
2015
2040
} catch ( rawError ) {
2016
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
2017
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
2041
+ const value = addError (
2042
+ rawError ,
2043
+ fieldNodes ,
2044
+ itemType ,
2045
+ itemPath ,
2046
+ asyncPayloadRecord . errors ,
2047
+ ) ;
2018
2048
// don't continue if iterator throws
2019
2049
return { done : true , value } ;
2020
2050
}
0 commit comments