@@ -748,17 +748,27 @@ 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 (
752
+ rawError ,
753
+ exeContext ,
754
+ fieldNodes ,
755
+ returnType ,
756
+ path ,
757
+ asyncPayloadRecord ,
758
+ ) ;
754
759
return null ;
755
760
} ) ;
756
761
}
757
762
return completed ;
758
763
} catch ( rawError ) {
759
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
760
- addError ( rawError , fieldNodes , returnType , path , errors ) ;
761
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
764
+ handleRawError (
765
+ rawError ,
766
+ exeContext ,
767
+ fieldNodes ,
768
+ returnType ,
769
+ path ,
770
+ asyncPayloadRecord ,
771
+ ) ;
762
772
return null ;
763
773
}
764
774
}
@@ -790,6 +800,19 @@ export function buildResolveInfo(
790
800
} ;
791
801
}
792
802
803
+ function handleRawError (
804
+ rawError : unknown ,
805
+ exeContext : ExecutionContext ,
806
+ fieldNodes : ReadonlyArray < FieldNode > ,
807
+ returnType : GraphQLOutputType ,
808
+ path : Path ,
809
+ asyncPayloadRecord : AsyncPayloadRecord | undefined ,
810
+ ) : void {
811
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
812
+ addError ( rawError , fieldNodes , returnType , path , errors ) ;
813
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
814
+ }
815
+
793
816
function addError (
794
817
rawError : unknown ,
795
818
fieldNodes : ReadonlyArray < FieldNode > ,
@@ -948,9 +971,14 @@ async function completePromisedValue(
948
971
}
949
972
return completed ;
950
973
} catch ( rawError ) {
951
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
952
- addError ( rawError , fieldNodes , returnType , path , errors ) ;
953
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
974
+ handleRawError (
975
+ rawError ,
976
+ exeContext ,
977
+ fieldNodes ,
978
+ returnType ,
979
+ path ,
980
+ asyncPayloadRecord ,
981
+ ) ;
954
982
return null ;
955
983
}
956
984
}
@@ -1025,7 +1053,6 @@ async function completeAsyncIteratorValue(
1025
1053
iterator : AsyncIterator < unknown > ,
1026
1054
asyncPayloadRecord ?: AsyncPayloadRecord ,
1027
1055
) : Promise < ReadonlyArray < unknown > > {
1028
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1029
1056
const stream = getStreamValues ( exeContext , fieldNodes , path ) ;
1030
1057
let containsPromise = false ;
1031
1058
const completedResults : Array < unknown > = [ ] ;
@@ -1058,6 +1085,7 @@ async function completeAsyncIteratorValue(
1058
1085
// eslint-disable-next-line no-await-in-loop
1059
1086
iteration = await iterator . next ( ) ;
1060
1087
} catch ( rawError ) {
1088
+ const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1061
1089
addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1062
1090
completedResults . push ( null ) ;
1063
1091
break ;
@@ -1071,7 +1099,6 @@ async function completeAsyncIteratorValue(
1071
1099
completeListItemValue (
1072
1100
iteration . value ,
1073
1101
completedResults ,
1074
- errors ,
1075
1102
exeContext ,
1076
1103
itemType ,
1077
1104
fieldNodes ,
@@ -1101,7 +1128,6 @@ function completeListValue(
1101
1128
asyncPayloadRecord ?: AsyncPayloadRecord ,
1102
1129
) : PromiseOrValue < ReadonlyArray < unknown > > {
1103
1130
const itemType = returnType . ofType ;
1104
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
1105
1131
1106
1132
if ( isAsyncIterable ( result ) ) {
1107
1133
const iterator = result [ Symbol . asyncIterator ] ( ) ;
@@ -1160,7 +1186,6 @@ function completeListValue(
1160
1186
completeListItemValue (
1161
1187
item ,
1162
1188
completedResults ,
1163
- errors ,
1164
1189
exeContext ,
1165
1190
itemType ,
1166
1191
fieldNodes ,
@@ -1186,7 +1211,6 @@ function completeListValue(
1186
1211
function completeListItemValue (
1187
1212
item : unknown ,
1188
1213
completedResults : Array < unknown > ,
1189
- errors : Array < GraphQLError > ,
1190
1214
exeContext : ExecutionContext ,
1191
1215
itemType : GraphQLOutputType ,
1192
1216
fieldNodes : ReadonlyArray < FieldNode > ,
@@ -1226,8 +1250,14 @@ function completeListItemValue(
1226
1250
// to take a second callback for the error case.
1227
1251
completedResults . push (
1228
1252
completedItem . then ( undefined , ( rawError ) => {
1229
- addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1230
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1253
+ handleRawError (
1254
+ rawError ,
1255
+ exeContext ,
1256
+ fieldNodes ,
1257
+ itemType ,
1258
+ itemPath ,
1259
+ asyncPayloadRecord ,
1260
+ ) ;
1231
1261
return null ;
1232
1262
} ) ,
1233
1263
) ;
@@ -1237,8 +1267,14 @@ function completeListItemValue(
1237
1267
1238
1268
completedResults . push ( completedItem ) ;
1239
1269
} catch ( rawError ) {
1240
- addError ( rawError , fieldNodes , itemType , itemPath , errors ) ;
1241
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1270
+ handleRawError (
1271
+ rawError ,
1272
+ exeContext ,
1273
+ fieldNodes ,
1274
+ itemType ,
1275
+ itemPath ,
1276
+ asyncPayloadRecord ,
1277
+ ) ;
1242
1278
completedResults . push ( null ) ;
1243
1279
}
1244
1280
@@ -1853,15 +1889,15 @@ function executeStreamField(
1853
1889
asyncPayloadRecord ,
1854
1890
) ;
1855
1891
} catch ( rawError ) {
1856
- addError (
1892
+ handleRawError (
1857
1893
rawError ,
1894
+ exeContext ,
1858
1895
fieldNodes ,
1859
1896
itemType ,
1860
1897
itemPath ,
1861
- asyncPayloadRecord . errors ,
1898
+ asyncPayloadRecord ,
1862
1899
) ;
1863
1900
completedItem = null ;
1864
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1865
1901
}
1866
1902
} catch ( error ) {
1867
1903
asyncPayloadRecord . errors . push ( error ) ;
@@ -1873,14 +1909,14 @@ function executeStreamField(
1873
1909
if ( isPromise ( completedItem ) ) {
1874
1910
const completedItems = completedItem
1875
1911
. then ( undefined , ( rawError ) => {
1876
- addError (
1912
+ handleRawError (
1877
1913
rawError ,
1914
+ exeContext ,
1878
1915
fieldNodes ,
1879
1916
itemType ,
1880
1917
itemPath ,
1881
- asyncPayloadRecord . errors ,
1918
+ asyncPayloadRecord ,
1882
1919
) ;
1883
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1884
1920
return null ;
1885
1921
} )
1886
1922
. then (
@@ -1945,27 +1981,27 @@ async function executeStreamIteratorItem(
1945
1981
1946
1982
if ( isPromise ( completedItem ) ) {
1947
1983
completedItem = completedItem . then ( undefined , ( rawError ) => {
1948
- addError (
1984
+ handleRawError (
1949
1985
rawError ,
1986
+ exeContext ,
1950
1987
fieldNodes ,
1951
1988
itemType ,
1952
1989
itemPath ,
1953
- asyncPayloadRecord . errors ,
1990
+ asyncPayloadRecord ,
1954
1991
) ;
1955
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1956
1992
return null ;
1957
1993
} ) ;
1958
1994
}
1959
1995
return { done : false , value : completedItem } ;
1960
1996
} catch ( rawError ) {
1961
- addError (
1997
+ handleRawError (
1962
1998
rawError ,
1999
+ exeContext ,
1963
2000
fieldNodes ,
1964
2001
itemType ,
1965
2002
itemPath ,
1966
- asyncPayloadRecord . errors ,
2003
+ asyncPayloadRecord ,
1967
2004
) ;
1968
- filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1969
2005
return { done : false , value : null } ;
1970
2006
}
1971
2007
}
0 commit comments