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