@@ -748,17 +748,13 @@ function executeField(
748
748
// Note: we don't rely on a `catch` method, but we do expect "thenable"
749
749
// to take a second callback for the error case.
750
750
return completed . then ( undefined , ( rawError ) => {
751
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
752
- addError ( rawError , fieldNodes , returnType , path , errors ) ;
753
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
751
+ handleRawError ( rawError , exeContext , fieldNodes , returnType , path , asyncPayloadRecord ) ;
754
752
return null ;
755
753
} ) ;
756
754
}
757
755
return completed ;
758
756
} catch ( rawError ) {
759
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
760
- addError ( rawError , fieldNodes , returnType , path , errors ) ;
761
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
757
+ handleRawError ( rawError , exeContext , fieldNodes , returnType , path , asyncPayloadRecord ) ;
762
758
return null ;
763
759
}
764
760
}
@@ -790,6 +786,19 @@ export function buildResolveInfo(
790
786
} ;
791
787
}
792
788
789
+ function handleRawError (
790
+ rawError : unknown ,
791
+ exeContext : ExecutionContext ,
792
+ fieldNodes : ReadonlyArray < FieldNode > ,
793
+ returnType : GraphQLOutputType ,
794
+ path : Path ,
795
+ asyncPayloadRecord : AsyncPayloadRecord | undefined ,
796
+ ) : void {
797
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
798
+ addError ( rawError , fieldNodes , returnType , path , errors ) ;
799
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
800
+ }
801
+
793
802
function addError (
794
803
rawError : unknown ,
795
804
fieldNodes : ReadonlyArray < FieldNode > ,
@@ -948,9 +957,14 @@ async function completePromisedValue(
948
957
}
949
958
return completed ;
950
959
} catch ( rawError ) {
951
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
952
- addError ( rawError , fieldNodes , returnType , path , errors ) ;
953
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
960
+ handleRawError (
961
+ rawError ,
962
+ exeContext ,
963
+ fieldNodes ,
964
+ returnType ,
965
+ path ,
966
+ asyncPayloadRecord ,
967
+ ) ;
954
968
return null ;
955
969
}
956
970
}
@@ -1025,7 +1039,6 @@ async function completeAsyncIteratorValue(
1025
1039
iterator : AsyncIterator < unknown > ,
1026
1040
asyncPayloadRecord ?: AsyncPayloadRecord ,
1027
1041
) : Promise < ReadonlyArray < unknown > > {
1028
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1029
1042
const stream = getStreamValues ( exeContext , fieldNodes , path ) ;
1030
1043
let containsPromise = false ;
1031
1044
const completedResults : Array < unknown > = [ ] ;
@@ -1058,6 +1071,7 @@ async function completeAsyncIteratorValue(
1058
1071
// eslint-disable-next-line no-await-in-loop
1059
1072
iteration = await iterator . next ( ) ;
1060
1073
} catch ( rawError ) {
1074
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1061
1075
addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1062
1076
completedResults . push ( null ) ;
1063
1077
break ;
@@ -1071,7 +1085,6 @@ async function completeAsyncIteratorValue(
1071
1085
completeListItemValue (
1072
1086
iteration . value ,
1073
1087
completedResults ,
1074
- errors ,
1075
1088
exeContext ,
1076
1089
itemType ,
1077
1090
fieldNodes ,
@@ -1101,7 +1114,6 @@ function completeListValue(
1101
1114
asyncPayloadRecord ?: AsyncPayloadRecord ,
1102
1115
) : PromiseOrValue < ReadonlyArray < unknown > > {
1103
1116
const itemType = returnType . ofType ;
1104
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1105
1117
1106
1118
if ( isAsyncIterable ( result ) ) {
1107
1119
const iterator = result [ Symbol . asyncIterator ] ( ) ;
@@ -1160,7 +1172,6 @@ function completeListValue(
1160
1172
completeListItemValue (
1161
1173
item ,
1162
1174
completedResults ,
1163
- errors ,
1164
1175
exeContext ,
1165
1176
itemType ,
1166
1177
fieldNodes ,
@@ -1186,7 +1197,6 @@ function completeListValue(
1186
1197
function completeListItemValue (
1187
1198
item : unknown ,
1188
1199
completedResults : Array < unknown > ,
1189
- errors : Array < GraphQLError > ,
1190
1200
exeContext : ExecutionContext ,
1191
1201
itemType : GraphQLOutputType ,
1192
1202
fieldNodes : ReadonlyArray < FieldNode > ,
@@ -1226,8 +1236,14 @@ function completeListItemValue(
1226
1236
// to take a second callback for the error case.
1227
1237
completedResults . push (
1228
1238
completedItem . then ( undefined , ( rawError ) => {
1229
- addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1230
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1239
+ handleRawError (
1240
+ rawError ,
1241
+ exeContext ,
1242
+ fieldNodes ,
1243
+ itemType ,
1244
+ itemPath ,
1245
+ asyncPayloadRecord ,
1246
+ ) ;
1231
1247
return null ;
1232
1248
} ) ,
1233
1249
) ;
@@ -1237,8 +1253,14 @@ function completeListItemValue(
1237
1253
1238
1254
completedResults . push ( completedItem ) ;
1239
1255
} catch ( rawError ) {
1240
- addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1241
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1256
+ handleRawError (
1257
+ rawError ,
1258
+ exeContext ,
1259
+ fieldNodes ,
1260
+ itemType ,
1261
+ itemPath ,
1262
+ asyncPayloadRecord ,
1263
+ ) ;
1242
1264
completedResults . push ( null ) ;
1243
1265
}
1244
1266
@@ -1853,15 +1875,15 @@ function executeStreamField(
1853
1875
asyncPayloadRecord ,
1854
1876
) ;
1855
1877
} catch ( rawError ) {
1856
- addError (
1878
+ handleRawError (
1857
1879
rawError ,
1880
+ exeContext ,
1858
1881
fieldNodes ,
1859
1882
itemType ,
1860
1883
itemPath ,
1861
- asyncPayloadRecord . errors ,
1884
+ asyncPayloadRecord ,
1862
1885
) ;
1863
1886
completedItem = null ;
1864
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1865
1887
}
1866
1888
} catch ( error ) {
1867
1889
asyncPayloadRecord . errors . push ( error ) ;
@@ -1873,14 +1895,14 @@ function executeStreamField(
1873
1895
if ( isPromise ( completedItem ) ) {
1874
1896
const completedItems = completedItem
1875
1897
. then ( undefined , ( rawError ) => {
1876
- addError (
1898
+ handleRawError (
1877
1899
rawError ,
1900
+ exeContext ,
1878
1901
fieldNodes ,
1879
1902
itemType ,
1880
1903
itemPath ,
1881
- asyncPayloadRecord . errors ,
1904
+ asyncPayloadRecord ,
1882
1905
) ;
1883
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1884
1906
return null ;
1885
1907
} )
1886
1908
. then (
@@ -1945,27 +1967,27 @@ async function executeStreamIteratorItem(
1945
1967
1946
1968
if ( isPromise ( completedItem ) ) {
1947
1969
completedItem = completedItem . then ( undefined , ( rawError ) => {
1948
- addError (
1970
+ handleRawError (
1949
1971
rawError ,
1972
+ exeContext ,
1950
1973
fieldNodes ,
1951
1974
itemType ,
1952
1975
itemPath ,
1953
- asyncPayloadRecord . errors ,
1976
+ asyncPayloadRecord ,
1954
1977
) ;
1955
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1956
1978
return null ;
1957
1979
} ) ;
1958
1980
}
1959
1981
return { done : false , value : completedItem } ;
1960
1982
} catch ( rawError ) {
1961
- addError (
1983
+ handleRawError (
1962
1984
rawError ,
1985
+ exeContext ,
1963
1986
fieldNodes ,
1964
1987
itemType ,
1965
1988
itemPath ,
1966
- asyncPayloadRecord . errors ,
1989
+ asyncPayloadRecord ,
1967
1990
) ;
1968
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1969
1991
return { done : false , value : null } ;
1970
1992
}
1971
1993
}
0 commit comments