@@ -722,14 +722,24 @@ function executeField(
722722 const result = resolveFn ( source , args , contextValue , info ) ;
723723
724724 if ( isPromise ( result ) ) {
725- return completePromisedValue (
726- exeContext ,
727- returnType ,
728- fieldNodes ,
729- info ,
730- path ,
725+ return after (
731726 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+ } ,
733743 ) ;
734744 }
735745
@@ -917,41 +927,6 @@ function completeValue(
917927 ) ;
918928}
919929
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-
955930/**
956931 * Returns an object containing the `@stream` arguments if a field should be
957932 * streamed based on the experimental flag, stream directive present and
@@ -1189,14 +1164,28 @@ function completeListItemValue(
11891164) : boolean {
11901165 if ( isPromise ( item ) ) {
11911166 completedResults . push (
1192- completePromisedValue (
1193- exeContext ,
1194- itemType ,
1195- fieldNodes ,
1196- info ,
1197- itemPath ,
1167+ after (
11981168 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+ } ,
12001189 ) ,
12011190 ) ;
12021191
@@ -1917,15 +1906,30 @@ function executeStreamField(
19171906 exeContext,
19181907 } ) ;
19191908 if ( isPromise ( item ) ) {
1920- const completedItem = completePromisedValue (
1921- exeContext ,
1922- itemType ,
1923- fieldNodes ,
1924- info ,
1925- itemPath ,
1909+ const completedItem = after (
19261910 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+ } ,
19281931 ) ;
1932+
19291933 const completedItems = after (
19301934 completedItem ,
19311935 ( resolved ) => [ resolved ] ,
0 commit comments