@@ -687,7 +687,6 @@ function executeField(
687
687
path : Path ,
688
688
asyncPayloadRecord ?: AsyncPayloadRecord ,
689
689
) : PromiseOrValue < unknown > {
690
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
691
690
const fieldName = fieldNodes [ 0 ] . name . value ;
692
691
const fieldDef = exeContext . schema . getField ( parentType , fieldName ) ;
693
692
if ( ! fieldDef ) {
@@ -749,18 +748,18 @@ function executeField(
749
748
// Note: we don't rely on a `catch` method, but we do expect "thenable"
750
749
// to take a second callback for the error case.
751
750
return completed . then ( undefined , ( rawError ) => {
752
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
753
- const handledError = handleFieldError ( error , returnType , errors ) ;
751
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
752
+ addError ( rawError , fieldNodes , returnType , path , errors ) ;
754
753
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
755
- return handledError ;
754
+ return null ;
756
755
} ) ;
757
756
}
758
757
return completed ;
759
758
} catch ( rawError ) {
760
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
761
- const handledError = handleFieldError ( error , returnType , errors ) ;
759
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
760
+ addError ( rawError , fieldNodes , returnType , path , errors ) ;
762
761
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
763
- return handledError ;
762
+ return null ;
764
763
}
765
764
}
766
765
@@ -791,11 +790,15 @@ export function buildResolveInfo(
791
790
} ;
792
791
}
793
792
794
- function handleFieldError (
795
- error : GraphQLError ,
793
+ function addError (
794
+ rawError : unknown ,
795
+ fieldNodes : ReadonlyArray < FieldNode > ,
796
796
returnType : GraphQLOutputType ,
797
+ path : Path ,
797
798
errors : Array < GraphQLError > ,
798
- ) : null {
799
+ ) : void {
800
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
801
+
799
802
// If the field type is non-nullable, then it is resolved without any
800
803
// protection from errors, however it still properly locates the error.
801
804
if ( isNonNullType ( returnType ) ) {
@@ -805,7 +808,6 @@ function handleFieldError(
805
808
// Otherwise, error protection is applied, logging the error and resolving
806
809
// a null value for this field if one is encountered.
807
810
errors . push ( error ) ;
808
- return null ;
809
811
}
810
812
811
813
/**
@@ -947,10 +949,9 @@ async function completePromisedValue(
947
949
return completed ;
948
950
} catch ( rawError ) {
949
951
const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
950
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
951
- const handledError = handleFieldError ( error , returnType , errors ) ;
952
+ addError ( rawError , fieldNodes , returnType , path , errors ) ;
952
953
filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
953
- return handledError ;
954
+ return null ;
954
955
}
955
956
}
956
957
@@ -1057,8 +1058,8 @@ async function completeAsyncIteratorValue(
1057
1058
// eslint-disable-next-line no-await-in-loop
1058
1059
iteration = await iterator . next ( ) ;
1059
1060
} catch ( rawError ) {
1060
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1061
- completedResults . push ( handleFieldError ( error , itemType , errors ) ) ;
1061
+ addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1062
+ completedResults . push ( null ) ;
1062
1063
break ;
1063
1064
}
1064
1065
@@ -1225,14 +1226,9 @@ function completeListItemValue(
1225
1226
// to take a second callback for the error case.
1226
1227
completedResults . push (
1227
1228
completedItem . then ( undefined , ( rawError ) => {
1228
- const error = locatedError (
1229
- rawError ,
1230
- fieldNodes ,
1231
- pathToArray ( itemPath ) ,
1232
- ) ;
1233
- const handledError = handleFieldError ( error , itemType , errors ) ;
1229
+ addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1234
1230
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1235
- return handledError ;
1231
+ return null ;
1236
1232
} ) ,
1237
1233
) ;
1238
1234
@@ -1241,10 +1237,9 @@ function completeListItemValue(
1241
1237
1242
1238
completedResults . push ( completedItem ) ;
1243
1239
} catch ( rawError ) {
1244
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1245
- const handledError = handleFieldError ( error , itemType , errors ) ;
1240
+ addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1246
1241
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1247
- completedResults . push ( handledError ) ;
1242
+ completedResults . push ( null ) ;
1248
1243
}
1249
1244
1250
1245
return false ;
@@ -1858,12 +1853,14 @@ function executeStreamField(
1858
1853
asyncPayloadRecord ,
1859
1854
) ;
1860
1855
} catch ( rawError ) {
1861
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1862
- completedItem = handleFieldError (
1863
- error ,
1856
+ addError (
1857
+ rawError ,
1858
+ fieldNodes ,
1864
1859
itemType ,
1860
+ itemPath ,
1865
1861
asyncPayloadRecord . errors ,
1866
1862
) ;
1863
+ completedItem = null ;
1867
1864
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1868
1865
}
1869
1866
} catch ( error ) {
@@ -1876,14 +1873,15 @@ function executeStreamField(
1876
1873
if ( isPromise ( completedItem ) ) {
1877
1874
const completedItems = completedItem
1878
1875
. then ( undefined , ( rawError ) => {
1879
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1880
- const handledError = handleFieldError (
1881
- error ,
1876
+ addError (
1877
+ rawError ,
1878
+ fieldNodes ,
1882
1879
itemType ,
1880
+ itemPath ,
1883
1881
asyncPayloadRecord . errors ,
1884
1882
) ;
1885
1883
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1886
- return handledError ;
1884
+ return null ;
1887
1885
} )
1888
1886
. then (
1889
1887
( value ) => [ value ] ,
@@ -1915,10 +1913,15 @@ async function executeStreamIteratorItem(
1915
1913
try {
1916
1914
iteration = await iterator . next ( ) ;
1917
1915
} catch ( rawError ) {
1918
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1919
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
1916
+ addError (
1917
+ rawError ,
1918
+ fieldNodes ,
1919
+ itemType ,
1920
+ itemPath ,
1921
+ asyncPayloadRecord . errors ,
1922
+ ) ;
1920
1923
// don't continue if iterator throws
1921
- return { done : true , value } ;
1924
+ return { done : true , value : null } ;
1922
1925
}
1923
1926
1924
1927
const { done, value : item } = iteration ;
@@ -1942,22 +1945,28 @@ async function executeStreamIteratorItem(
1942
1945
1943
1946
if ( isPromise ( completedItem ) ) {
1944
1947
completedItem = completedItem . then ( undefined , ( rawError ) => {
1945
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1946
- const handledError = handleFieldError (
1947
- error ,
1948
+ addError (
1949
+ rawError ,
1950
+ fieldNodes ,
1948
1951
itemType ,
1952
+ itemPath ,
1949
1953
asyncPayloadRecord . errors ,
1950
1954
) ;
1951
1955
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1952
- return handledError ;
1956
+ return null ;
1953
1957
} ) ;
1954
1958
}
1955
1959
return { done : false , value : completedItem } ;
1956
1960
} catch ( rawError ) {
1957
- const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1958
- const value = handleFieldError ( error , itemType , asyncPayloadRecord . errors ) ;
1961
+ addError (
1962
+ rawError ,
1963
+ fieldNodes ,
1964
+ itemType ,
1965
+ itemPath ,
1966
+ asyncPayloadRecord . errors ,
1967
+ ) ;
1959
1968
filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1960
- return { done : false , value } ;
1969
+ return { done : false , value : null } ;
1961
1970
}
1962
1971
}
1963
1972
0 commit comments