@@ -234,7 +234,7 @@ export class Executor<
234234 abortReason : unknown ;
235235 sharedExecutionContext : SharedExecutionContext ;
236236 collectedErrors : CollectedErrors ;
237- abortResultPromise : ( ( reason ?: unknown ) => void ) | undefined ;
237+ abortResultPromise : ( ( ) => void ) | undefined ;
238238 resolverAbortController : AbortController | undefined ;
239239 getAbortSignal : ( ) => AbortSignal | undefined ;
240240 getAsyncHelpers : ( ) => GraphQLResolveInfoHelpers ;
@@ -285,6 +285,7 @@ export class Executor<
285285 removeExternalAbortListener ?.( ) ;
286286 } ;
287287
288+ let result : PromiseOrValue < ObjMap < unknown > > ;
288289 try {
289290 const {
290291 schema,
@@ -314,7 +315,7 @@ export class Executor<
314315 hideSuggestions ,
315316 ) ;
316317
317- const result = this . executeCollectedRootFields (
318+ result = this . executeCollectedRootFields (
318319 operation . operation ,
319320 rootType ,
320321 rootValue ,
@@ -336,26 +337,22 @@ export class Executor<
336337 ) ;
337338 this . sharedExecutionContext . asyncWorkTracker . add ( promise ) ;
338339 const { promise : cancellablePromise , abort : abortResultPromise } =
339- withCancellation ( promise ) ;
340- this . abortResultPromise = abortResultPromise ;
341- if ( this . aborted ) {
340+ withCancellation ( promise . then ( ( resolved ) => this . finish ( resolved ) ) ) ;
341+ this . abortResultPromise = ( ) => {
342342 abortResultPromise ( this . abortReason ) ;
343+ } ;
344+ if ( this . aborted ) {
345+ this . abortResultPromise ( ) ;
343346 }
344347 return cancellablePromise ;
345348 }
346349 maybeRemoveExternalAbortListener ( ) ;
347- return this . buildResponse ( result ) ;
348350 } catch ( error ) {
349351 maybeRemoveExternalAbortListener ( ) ;
350352 this . collectedErrors . add ( ensureGraphQLError ( error ) , undefined ) ;
351- return this . buildResponse ( null ) ;
352- }
353- }
354-
355- throwIfAborted ( ) : void {
356- if ( this . aborted ) {
357- throw this . abortReason ;
353+ return this . finish ( this . buildResponse ( null ) ) ;
358354 }
355+ return this . finish ( this . buildResponse ( result ) ) ;
359356 }
360357
361358 abort ( reason ?: unknown ) : void {
@@ -366,13 +363,16 @@ export class Executor<
366363 if ( reason !== undefined ) {
367364 this . abortReason = reason ;
368365 }
369- this . abortResultPromise ?.( this . abortReason ) ;
366+ this . abortResultPromise ?.( ) ;
370367 this . resolverAbortController ?. abort ( this . abortReason ) ;
371368 }
372369
373- finish ( ) : void {
374- this . throwIfAborted ( ) ;
370+ finish < T > ( result : T ) : T {
371+ if ( this . aborted ) {
372+ throw this . abortReason ;
373+ }
375374 this . aborted = true ;
375+ return result ;
376376 }
377377
378378 getFinishSharedExecution ( ) : ( ) => void {
@@ -403,10 +403,8 @@ export class Executor<
403403 data : ObjMap < unknown > | null ,
404404 ) : ExecutionResult | TAlternativeInitialResponse {
405405 this . getFinishSharedExecution ( ) ( ) ;
406- this . finish ( ) ;
407406 const errors = this . collectedErrors . errors ;
408- const result = errors . length ? { errors, data } : { data } ;
409- return result ;
407+ return errors . length ? { errors, data } : { data } ;
410408 }
411409
412410 executeCollectedRootFields (
0 commit comments