@@ -699,7 +699,6 @@ function executeField(
699
699
path : Path ,
700
700
asyncPayloadRecord ?: AsyncPayloadRecord ,
701
701
) : PromiseOrValue < unknown > {
702
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
703
702
const fieldName = fieldGroup [ 0 ] . name . value ;
704
703
const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
705
704
if ( ! fieldDef ) {
@@ -761,18 +760,30 @@ function executeField(
761
760
// Note: we don't rely on a `catch` method, but we do expect "thenable"
762
761
// to take a second callback for the error case.
763
762
return completed . then ( undefined , ( rawError ) => {
764
- const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
765
- const handledError = handleFieldError ( error , returnType , errors ) ;
763
+ handleFieldError (
764
+ rawError ,
765
+ exeContext ,
766
+ returnType ,
767
+ fieldGroup ,
768
+ path ,
769
+ asyncPayloadRecord ,
770
+ ) ;
766
771
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
767
- return handledError ;
772
+ return null ;
768
773
} ) ;
769
774
}
770
775
return completed ;
771
776
} catch ( rawError ) {
772
- const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
773
- const handledError = handleFieldError ( error , returnType , errors ) ;
777
+ handleFieldError (
778
+ rawError ,
779
+ exeContext ,
780
+ returnType ,
781
+ fieldGroup ,
782
+ path ,
783
+ asyncPayloadRecord ,
784
+ ) ;
774
785
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
775
- return handledError ;
786
+ return null ;
776
787
}
777
788
}
778
789
@@ -804,20 +815,26 @@ export function buildResolveInfo(
804
815
}
805
816
806
817
function handleFieldError (
807
- error : GraphQLError ,
818
+ rawError : unknown ,
819
+ exeContext : ExecutionContext ,
808
820
returnType : GraphQLOutputType ,
809
- errors : Array < GraphQLError > ,
810
- ) : null {
821
+ fieldGroup : FieldGroup ,
822
+ path : Path ,
823
+ asyncPayloadRecord ?: AsyncPayloadRecord | undefined ,
824
+ ) : void {
825
+ const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
826
+
811
827
// If the field type is non-nullable, then it is resolved without any
812
828
// protection from errors, however it still properly locates the error.
813
829
if ( isNonNullType ( returnType ) ) {
814
830
throw error ;
815
831
}
816
832
833
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
834
+
817
835
// Otherwise, error protection is applied, logging the error and resolving
818
836
// a null value for this field if one is encountered.
819
837
errors . push ( error ) ;
820
- return null ;
821
838
}
822
839
823
840
/**
@@ -958,11 +975,16 @@ async function completePromisedValue(
958
975
}
959
976
return completed ;
960
977
} catch ( rawError ) {
961
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
962
- const error = locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
963
- const handledError = handleFieldError ( error , returnType , errors ) ;
978
+ handleFieldError (
979
+ rawError ,
980
+ exeContext ,
981
+ returnType ,
982
+ fieldGroup ,
983
+ path ,
984
+ asyncPayloadRecord ,
985
+ ) ;
964
986
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
965
- return handledError ;
987
+ return null ;
966
988
}
967
989
}
968
990
@@ -1036,7 +1058,6 @@ async function completeAsyncIteratorValue(
1036
1058
iterator : AsyncIterator < unknown > ,
1037
1059
asyncPayloadRecord ?: AsyncPayloadRecord ,
1038
1060
) : Promise < ReadonlyArray < unknown > > {
1039
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1040
1061
const stream = getStreamValues ( exeContext , fieldGroup , path ) ;
1041
1062
let containsPromise = false ;
1042
1063
const completedResults : Array < unknown > = [ ] ;
@@ -1072,16 +1093,22 @@ async function completeAsyncIteratorValue(
1072
1093
break ;
1073
1094
}
1074
1095
} catch ( rawError ) {
1075
- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
1076
- completedResults . push ( handleFieldError ( error , itemType , errors ) ) ;
1096
+ handleFieldError (
1097
+ rawError ,
1098
+ exeContext ,
1099
+ itemType ,
1100
+ fieldGroup ,
1101
+ itemPath ,
1102
+ asyncPayloadRecord ,
1103
+ ) ;
1104
+ completedResults . push ( null ) ;
1077
1105
break ;
1078
1106
}
1079
1107
1080
1108
if (
1081
1109
completeListItemValue (
1082
1110
iteration . value ,
1083
1111
completedResults ,
1084
- errors ,
1085
1112
exeContext ,
1086
1113
itemType ,
1087
1114
fieldGroup ,
@@ -1111,7 +1138,6 @@ function completeListValue(
1111
1138
asyncPayloadRecord ?: AsyncPayloadRecord ,
1112
1139
) : PromiseOrValue < ReadonlyArray < unknown > > {
1113
1140
const itemType = returnType . ofType ;
1114
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1115
1141
1116
1142
if ( isAsyncIterable ( result ) ) {
1117
1143
const iterator = result [ Symbol . asyncIterator ] ( ) ;
@@ -1170,7 +1196,6 @@ function completeListValue(
1170
1196
completeListItemValue (
1171
1197
item ,
1172
1198
completedResults ,
1173
- errors ,
1174
1199
exeContext ,
1175
1200
itemType ,
1176
1201
fieldGroup ,
@@ -1196,7 +1221,6 @@ function completeListValue(
1196
1221
function completeListItemValue (
1197
1222
item : unknown ,
1198
1223
completedResults : Array < unknown > ,
1199
- errors : Array < GraphQLError > ,
1200
1224
exeContext : ExecutionContext ,
1201
1225
itemType : GraphQLOutputType ,
1202
1226
fieldGroup : FieldGroup ,
@@ -1236,14 +1260,16 @@ function completeListItemValue(
1236
1260
// to take a second callback for the error case.
1237
1261
completedResults . push (
1238
1262
completedItem . then ( undefined , ( rawError ) => {
1239
- const error = locatedError (
1263
+ handleFieldError (
1240
1264
rawError ,
1265
+ exeContext ,
1266
+ itemType ,
1241
1267
fieldGroup ,
1242
- pathToArray ( itemPath ) ,
1268
+ itemPath ,
1269
+ asyncPayloadRecord ,
1243
1270
) ;
1244
- const handledError = handleFieldError ( error , itemType , errors ) ;
1245
1271
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1246
- return handledError ;
1272
+ return null ;
1247
1273
} ) ,
1248
1274
) ;
1249
1275
@@ -1252,10 +1278,16 @@ function completeListItemValue(
1252
1278
1253
1279
completedResults . push ( completedItem ) ;
1254
1280
} catch ( rawError ) {
1255
- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
1256
- const handledError = handleFieldError ( error , itemType , errors ) ;
1281
+ handleFieldError (
1282
+ rawError ,
1283
+ exeContext ,
1284
+ itemType ,
1285
+ fieldGroup ,
1286
+ itemPath ,
1287
+ asyncPayloadRecord ,
1288
+ ) ;
1257
1289
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1258
- completedResults . push ( handledError ) ;
1290
+ completedResults . push ( null ) ;
1259
1291
}
1260
1292
1261
1293
return false ;
@@ -1866,12 +1898,15 @@ function executeStreamField(
1866
1898
asyncPayloadRecord ,
1867
1899
) ;
1868
1900
} catch ( rawError ) {
1869
- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
1870
- completedItem = handleFieldError (
1871
- error ,
1901
+ handleFieldError (
1902
+ rawError ,
1903
+ exeContext ,
1872
1904
itemType ,
1873
- asyncPayloadRecord . errors ,
1905
+ fieldGroup ,
1906
+ itemPath ,
1907
+ asyncPayloadRecord ,
1874
1908
) ;
1909
+ completedItem = null ;
1875
1910
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1876
1911
}
1877
1912
} catch ( error ) {
@@ -1884,14 +1919,16 @@ function executeStreamField(
1884
1919
if ( isPromise ( completedItem ) ) {
1885
1920
const completedItems = completedItem
1886
1921
. then ( undefined , ( rawError ) => {
1887
- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
1888
- const handledError = handleFieldError (
1889
- error ,
1922
+ handleFieldError (
1923
+ rawError ,
1924
+ exeContext ,
1890
1925
itemType ,
1891
- asyncPayloadRecord . errors ,
1926
+ fieldGroup ,
1927
+ itemPath ,
1928
+ asyncPayloadRecord ,
1892
1929
) ;
1893
1930
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1894
- return handledError ;
1931
+ return null ;
1895
1932
} )
1896
1933
. then (
1897
1934
( value ) => [ value ] ,
@@ -1928,10 +1965,16 @@ async function executeStreamIteratorItem(
1928
1965
}
1929
1966
item = value ;
1930
1967
} catch ( rawError ) {
1931
- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
1932
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
1968
+ handleFieldError (
1969
+ rawError ,
1970
+ exeContext ,
1971
+ itemType ,
1972
+ fieldGroup ,
1973
+ itemPath ,
1974
+ asyncPayloadRecord ,
1975
+ ) ;
1933
1976
// don't continue if iterator throws
1934
- return { done : true , value } ;
1977
+ return { done : true , value : null } ;
1935
1978
}
1936
1979
let completedItem ;
1937
1980
try {
@@ -1947,22 +1990,30 @@ async function executeStreamIteratorItem(
1947
1990
1948
1991
if ( isPromise ( completedItem ) ) {
1949
1992
completedItem = completedItem . then ( undefined , ( rawError ) => {
1950
- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
1951
- const handledError = handleFieldError (
1952
- error ,
1993
+ handleFieldError (
1994
+ rawError ,
1995
+ exeContext ,
1953
1996
itemType ,
1954
- asyncPayloadRecord . errors ,
1997
+ fieldGroup ,
1998
+ itemPath ,
1999
+ asyncPayloadRecord ,
1955
2000
) ;
1956
2001
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1957
- return handledError ;
2002
+ return null ;
1958
2003
} ) ;
1959
2004
}
1960
2005
return { done : false , value : completedItem } ;
1961
2006
} catch ( rawError ) {
1962
- const error = locatedError ( rawError , fieldGroup , pathToArray ( itemPath ) ) ;
1963
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
2007
+ handleFieldError (
2008
+ rawError ,
2009
+ exeContext ,
2010
+ itemType ,
2011
+ fieldGroup ,
2012
+ itemPath ,
2013
+ asyncPayloadRecord ,
2014
+ ) ;
1964
2015
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1965
- return { done : false , value } ;
2016
+ return { done : false , value : null } ;
1966
2017
}
1967
2018
}
1968
2019
0 commit comments