@@ -671,7 +671,6 @@ function executeField(
671
671
path : Path ,
672
672
asyncPayloadRecord ?: AsyncPayloadRecord ,
673
673
) : PromiseOrValue < unknown > {
674
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
675
674
const fieldName = fieldNodes [ 0 ] . name . value ;
676
675
const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
677
676
if ( ! fieldDef ) {
@@ -708,8 +707,14 @@ function executeField(
708
707
709
708
result = resolveFn ( source , args , contextValue , info ) ;
710
709
} catch ( rawError ) {
711
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
712
- const handledError = handleFieldError ( error , returnType , errors ) ;
710
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . 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
}
@@ -764,11 +769,15 @@ export function buildResolveInfo(
764
769
} ;
765
770
}
766
771
767
- function handleFieldError (
768
- error : GraphQLError ,
772
+ function addError (
773
+ rawError : unknown ,
774
+ fieldNodes : ReadonlyArray < FieldNode > ,
769
775
returnType : GraphQLOutputType ,
776
+ path : Path ,
770
777
errors : Array < GraphQLError > ,
771
778
) : null {
779
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
780
+
772
781
// If the field type is non-nullable, then it is resolved without any
773
782
// protection from errors, however it still properly locates the error.
774
783
if ( isNonNullType ( returnType ) ) {
@@ -922,8 +931,13 @@ async function completePromiseCatchingErrors(
922
931
return completed ;
923
932
} catch ( rawError ) {
924
933
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
925
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
926
- const handledError = handleFieldError ( error , returnType , errors ) ;
934
+ const handledError = addError (
935
+ rawError ,
936
+ fieldNodes ,
937
+ returnType ,
938
+ path ,
939
+ errors ,
940
+ ) ;
927
941
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
928
942
return handledError ;
929
943
}
@@ -951,8 +965,13 @@ function completeValueCatchingErrors(
951
965
) ;
952
966
} catch ( rawError ) {
953
967
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
954
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
955
- const handledError = handleFieldError ( error , returnType , errors ) ;
968
+ const handledError = addError (
969
+ rawError ,
970
+ fieldNodes ,
971
+ returnType ,
972
+ path ,
973
+ errors ,
974
+ ) ;
956
975
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
957
976
return handledError ;
958
977
}
@@ -962,8 +981,13 @@ function completeValueCatchingErrors(
962
981
// to take a second callback for the error case.
963
982
completedValue = completedValue . then ( undefined , ( rawError ) => {
964
983
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
965
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
966
- const handledError = handleFieldError ( error , returnType , errors ) ;
984
+ const handledError = addError (
985
+ rawError ,
986
+ fieldNodes ,
987
+ returnType ,
988
+ path ,
989
+ errors ,
990
+ ) ;
967
991
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
968
992
return handledError ;
969
993
} ) ;
@@ -1069,8 +1093,9 @@ async function completeAsyncIteratorValue(
1069
1093
// eslint-disable-next-line no-await-in-loop
1070
1094
iteration = await iterator . next ( ) ;
1071
1095
} catch ( rawError ) {
1072
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1073
- completedResults . push ( handleFieldError ( error , itemType , errors ) ) ;
1096
+ completedResults . push (
1097
+ addError ( rawError , fieldNodes , itemType , itemPath , errors ) ,
1098
+ ) ;
1074
1099
break ;
1075
1100
}
1076
1101
@@ -2016,8 +2041,13 @@ async function executeStreamAsyncIteratorItem(
2016
2041
try {
2017
2042
iteration = await iterator . next ( ) ;
2018
2043
} catch ( rawError ) {
2019
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
2020
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
2044
+ const value = addError (
2045
+ rawError ,
2046
+ fieldNodes ,
2047
+ itemType ,
2048
+ itemPath ,
2049
+ asyncPayloadRecord . errors ,
2050
+ ) ;
2021
2051
// don't continue if iterator throws
2022
2052
return { done : true , value } ;
2023
2053
}
0 commit comments