@@ -13,6 +13,7 @@ import { addPath, pathToArray } from '../jsutils/Path.js';
1313import { promiseForObject } from '../jsutils/promiseForObject.js' ;
1414import type { PromiseOrValue } from '../jsutils/PromiseOrValue.js' ;
1515import { promiseReduce } from '../jsutils/promiseReduce.js' ;
16+ import { promiseWithResolvers } from '../jsutils/promiseWithResolvers.js' ;
1617
1718import { GraphQLError } from '../error/GraphQLError.js' ;
1819import { locatedError } from '../error/locatedError.js' ;
@@ -867,41 +868,42 @@ function executeField(
867868 const result = resolveFn ( source , args , contextValue , info , abortSignal ) ;
868869
869870 if ( isPromise ( result ) ) {
870- return new Promise ( ( resolve , reject ) => {
871- abortSignal ?. addEventListener (
872- 'abort' ,
873- ( ) => {
874- try {
875- resolve ( {
876- rawResult : null ,
877- incrementalDataRecords : undefined ,
878- errors : [
879- buildFieldError (
880- abortSignal . reason ,
881- returnType ,
882- fieldDetailsList ,
883- path ,
884- ) ,
885- ] ,
886- } ) ;
887- } catch ( error ) {
888- reject ( error as GraphQLError ) ;
889- }
890- } ,
891- { once : true } ,
892- ) ;
893- completePromisedValue (
894- exeContext ,
895- returnType ,
896- fieldDetailsList ,
897- info ,
898- path ,
899- result ,
900- incrementalContext ,
901- deferMap ,
902- // eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
903- ) . then ( resolve , reject ) ;
904- } ) ;
871+ const { promise, resolve, reject } =
872+ promiseWithResolvers < GraphQLWrappedResult < unknown > > ( ) ;
873+ abortSignal ?. addEventListener (
874+ 'abort' ,
875+ ( ) => {
876+ try {
877+ resolve ( {
878+ rawResult : null ,
879+ incrementalDataRecords : undefined ,
880+ errors : [
881+ buildFieldError (
882+ abortSignal . reason ,
883+ returnType ,
884+ fieldDetailsList ,
885+ path ,
886+ ) ,
887+ ] ,
888+ } ) ;
889+ } catch ( error ) {
890+ reject ( error ) ;
891+ }
892+ } ,
893+ { once : true } ,
894+ ) ;
895+ completePromisedValue (
896+ exeContext ,
897+ returnType ,
898+ fieldDetailsList ,
899+ info ,
900+ path ,
901+ result ,
902+ incrementalContext ,
903+ deferMap ,
904+ // eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
905+ ) . then ( resolve , reject ) ;
906+ return promise ;
905907 }
906908
907909 const completed = completeValue (
@@ -2204,18 +2206,19 @@ function executeSubscription(
22042206 const result = resolveFn ( rootValue , args , contextValue , info , abortSignal ) ;
22052207
22062208 if ( isPromise ( result ) ) {
2207- return new Promise ( ( resolve , reject ) => {
2208- abortSignal ?. addEventListener (
2209- 'abort' ,
2210- ( ) =>
2211- reject (
2212- locatedError ( abortSignal . reason , fieldNodes , pathToArray ( path ) ) ,
2213- ) ,
2214- { once : true } ,
2215- ) ;
2216- // eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
2217- result . then ( resolve , reject ) ;
2218- } )
2209+ const { promise, resolve, reject } = promiseWithResolvers < unknown > ( ) ;
2210+ abortSignal ?. addEventListener (
2211+ 'abort' ,
2212+ ( ) =>
2213+ reject (
2214+ locatedError ( abortSignal . reason , fieldNodes , pathToArray ( path ) ) ,
2215+ ) ,
2216+ { once : true } ,
2217+ ) ;
2218+ // eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
2219+ result . then ( resolve , reject ) ;
2220+
2221+ return promise
22192222 . then ( assertEventStream )
22202223 . then ( undefined , ( error : unknown ) => {
22212224 throw locatedError ( error , fieldNodes , pathToArray ( path ) ) ;
0 commit comments