@@ -722,14 +722,24 @@ function executeField(
722
722
const result = resolveFn ( source , args , contextValue , info ) ;
723
723
724
724
if ( isPromise ( result ) ) {
725
- return completePromisedValue (
726
- exeContext ,
727
- returnType ,
728
- fieldNodes ,
729
- info ,
730
- path ,
725
+ return after (
731
726
result ,
732
- asyncPayloadRecord ,
727
+ ( resolved ) =>
728
+ completeValue (
729
+ exeContext ,
730
+ returnType ,
731
+ fieldNodes ,
732
+ info ,
733
+ path ,
734
+ resolved ,
735
+ asyncPayloadRecord ,
736
+ ) ,
737
+ ( rawError ) => {
738
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
739
+ const handledError = handleFieldError ( error , returnType , errors ) ;
740
+ filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
741
+ return handledError ;
742
+ } ,
733
743
) ;
734
744
}
735
745
@@ -917,41 +927,6 @@ function completeValue(
917
927
) ;
918
928
}
919
929
920
- async function completePromisedValue (
921
- exeContext : ExecutionContext ,
922
- returnType : GraphQLOutputType ,
923
- fieldNodes : ReadonlyArray < FieldNode > ,
924
- info : GraphQLResolveInfo ,
925
- path : Path ,
926
- result : Promise < unknown > ,
927
- asyncPayloadRecord ?: AsyncPayloadRecord ,
928
- ) : Promise < unknown > {
929
- try {
930
- const resolved = await result ;
931
- let completed = completeValue (
932
- exeContext ,
933
- returnType ,
934
- fieldNodes ,
935
- info ,
936
- path ,
937
- resolved ,
938
- asyncPayloadRecord ,
939
- ) ;
940
- if ( isPromise ( completed ) ) {
941
- // see: https://github.com/tc39/proposal-faster-promise-adoption
942
- // it is faster to await a promise prior to returning it from an async function
943
- completed = await completed ;
944
- }
945
- return completed ;
946
- } catch ( rawError ) {
947
- const errors = asyncPayloadRecord ?. errors ?? exeContext . errors ;
948
- const error = locatedError ( rawError , fieldNodes , pathToArray ( path ) ) ;
949
- const handledError = handleFieldError ( error , returnType , errors ) ;
950
- filterSubsequentPayloads ( exeContext , path , asyncPayloadRecord ) ;
951
- return handledError ;
952
- }
953
- }
954
-
955
930
/**
956
931
* Returns an object containing the `@stream` arguments if a field should be
957
932
* streamed based on the experimental flag, stream directive present and
@@ -1189,14 +1164,28 @@ function completeListItemValue(
1189
1164
) : boolean {
1190
1165
if ( isPromise ( item ) ) {
1191
1166
completedResults . push (
1192
- completePromisedValue (
1193
- exeContext ,
1194
- itemType ,
1195
- fieldNodes ,
1196
- info ,
1197
- itemPath ,
1167
+ after (
1198
1168
item ,
1199
- asyncPayloadRecord ,
1169
+ ( resolved ) =>
1170
+ completeValue (
1171
+ exeContext ,
1172
+ itemType ,
1173
+ fieldNodes ,
1174
+ info ,
1175
+ itemPath ,
1176
+ resolved ,
1177
+ asyncPayloadRecord ,
1178
+ ) ,
1179
+ ( rawError ) => {
1180
+ const error = locatedError (
1181
+ rawError ,
1182
+ fieldNodes ,
1183
+ pathToArray ( itemPath ) ,
1184
+ ) ;
1185
+ const handledError = handleFieldError ( error , itemType , errors ) ;
1186
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1187
+ return handledError ;
1188
+ } ,
1200
1189
) ,
1201
1190
) ;
1202
1191
@@ -1917,15 +1906,30 @@ function executeStreamField(
1917
1906
exeContext,
1918
1907
} ) ;
1919
1908
if ( isPromise ( item ) ) {
1920
- const completedItem = completePromisedValue (
1921
- exeContext ,
1922
- itemType ,
1923
- fieldNodes ,
1924
- info ,
1925
- itemPath ,
1909
+ const completedItem = after (
1926
1910
item ,
1927
- asyncPayloadRecord ,
1911
+ ( resolved ) =>
1912
+ completeValue (
1913
+ exeContext ,
1914
+ itemType ,
1915
+ fieldNodes ,
1916
+ info ,
1917
+ itemPath ,
1918
+ resolved ,
1919
+ asyncPayloadRecord ,
1920
+ ) ,
1921
+ ( rawError ) => {
1922
+ const error = locatedError ( rawError , fieldNodes , pathToArray ( itemPath ) ) ;
1923
+ const handledError = handleFieldError (
1924
+ error ,
1925
+ itemType ,
1926
+ asyncPayloadRecord . errors ,
1927
+ ) ;
1928
+ filterSubsequentPayloads ( exeContext , itemPath , asyncPayloadRecord ) ;
1929
+ return handledError ;
1930
+ } ,
1928
1931
) ;
1932
+
1929
1933
const completedItems = after (
1930
1934
completedItem ,
1931
1935
( resolved ) => [ resolved ] ,
0 commit comments