@@ -668,7 +668,6 @@ function executeField(
668
668
path : Path ,
669
669
asyncPayloadRecord ?: AsyncPayloadRecord ,
670
670
) : PromiseOrValue < unknown > {
671
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
672
671
const fieldName = fieldNodes [ 0 ] . name . value ;
673
672
const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
674
673
if ( ! fieldDef ) {
@@ -705,8 +704,14 @@ function executeField(
705
704
706
705
result = resolveFn ( source , args , contextValue , info ) ;
707
706
} catch ( rawError ) {
708
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
709
- const handledError = handleFieldError ( error , returnType , errors ) ;
707
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
708
+ const handledError = addError (
709
+ rawError ,
710
+ fieldNodes ,
711
+ returnType ,
712
+ path ,
713
+ errors ,
714
+ ) ;
710
715
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
711
716
return handledError ;
712
717
}
@@ -761,11 +766,15 @@ export function buildResolveInfo(
761
766
} ;
762
767
}
763
768
764
- function handleFieldError (
765
- error : GraphQLError ,
769
+ function addError (
770
+ rawError : unknown ,
771
+ fieldNodes : ReadonlyArray < FieldNode > ,
766
772
returnType : GraphQLOutputType ,
773
+ path : Path ,
767
774
errors : Array < GraphQLError > ,
768
775
) : null {
776
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
777
+
769
778
// If the field type is non-nullable, then it is resolved without any
770
779
// protection from errors, however it still properly locates the error.
771
780
if ( isNonNullType ( returnType ) ) {
@@ -919,8 +928,13 @@ async function completePromiseCatchingErrors(
919
928
return completed ;
920
929
} catch ( rawError ) {
921
930
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
922
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
923
- const handledError = handleFieldError ( error , returnType , errors ) ;
931
+ const handledError = addError (
932
+ rawError ,
933
+ fieldNodes ,
934
+ returnType ,
935
+ path ,
936
+ errors ,
937
+ ) ;
924
938
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
925
939
return handledError ;
926
940
}
@@ -948,8 +962,13 @@ function completeValueCatchingErrors(
948
962
) ;
949
963
} catch ( rawError ) {
950
964
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
951
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
952
- const handledError = handleFieldError ( error , returnType , errors ) ;
965
+ const handledError = addError (
966
+ rawError ,
967
+ fieldNodes ,
968
+ returnType ,
969
+ path ,
970
+ errors ,
971
+ ) ;
953
972
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
954
973
return handledError ;
955
974
}
@@ -959,8 +978,13 @@ function completeValueCatchingErrors(
959
978
// to take a second callback for the error case.
960
979
completedValue = completedValue . then ( undefined , ( rawError ) => {
961
980
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
962
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
963
- const handledError = handleFieldError ( error , returnType , errors ) ;
981
+ const handledError = addError (
982
+ rawError ,
983
+ fieldNodes ,
984
+ returnType ,
985
+ path ,
986
+ errors ,
987
+ ) ;
964
988
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
965
989
return handledError ;
966
990
} ) ;
@@ -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
@@ -1958,8 +1983,13 @@ async function executeStreamIteratorItem(
1958
1983
try {
1959
1984
iteration = await iterator . next ( ) ;
1960
1985
} catch ( rawError ) {
1961
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1962
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
1986
+ const value = addError (
1987
+ rawError ,
1988
+ fieldNodes ,
1989
+ itemType ,
1990
+ itemPath ,
1991
+ asyncPayloadRecord . errors ,
1992
+ ) ;
1963
1993
// don't continue if iterator throws
1964
1994
return { done : true , value } ;
1965
1995
}
0 commit comments