@@ -165,11 +165,13 @@ export interface ExecutionContext {
165165 validatedExecutionArgs : ValidatedExecutionArgs ;
166166 errors : Array < GraphQLError > | undefined ;
167167 canceller : Canceller ;
168+ completed : boolean ;
168169 cancellableStreams : Set < CancellableStreamRecord > | undefined ;
169170}
170171
171172interface IncrementalContext {
172173 errors : Array < GraphQLError > | undefined ;
174+ completed : boolean ;
173175 deferUsageSet ?: DeferUsageSet | undefined ;
174176}
175177
@@ -316,6 +318,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
316318 validatedExecutionArgs,
317319 errors : undefined ,
318320 canceller : new Canceller ( validatedExecutionArgs . abortSignal ) ,
321+ completed : false ,
319322 cancellableStreams : undefined ,
320323 } ;
321324 try {
@@ -366,8 +369,12 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
366369
367370 if ( isPromise ( graphqlWrappedResult ) ) {
368371 return graphqlWrappedResult . then (
369- ( resolved ) => buildDataResponse ( exeContext , resolved ) ,
372+ ( resolved ) => {
373+ exeContext . completed = true ;
374+ return buildDataResponse ( exeContext , resolved ) ;
375+ } ,
370376 ( error : unknown ) => {
377+ exeContext . completed = true ;
371378 exeContext . canceller . unsubscribe ( ) ;
372379 return {
373380 data : null ,
@@ -376,8 +383,10 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
376383 } ,
377384 ) ;
378385 }
386+ exeContext . completed = true ;
379387 return buildDataResponse ( exeContext , graphqlWrappedResult ) ;
380388 } catch ( error ) {
389+ exeContext . completed = true ;
381390 exeContext . canceller . unsubscribe ( ) ;
382391 return { data : null , errors : withError ( exeContext . errors , error ) } ;
383392 }
@@ -825,7 +834,7 @@ function executeField(
825834 validatedExecutionArgs ;
826835 const fieldName = fieldDetailsList [ 0 ] . node . name . value ;
827836 const fieldDef = schema . getField ( parentType , fieldName ) ;
828- if ( ! fieldDef ) {
837+ if ( ! fieldDef || ( incrementalContext ?? exeContext ) . completed ) {
829838 return ;
830839 }
831840
@@ -2271,6 +2280,7 @@ function collectExecutionGroups(
22712280 groupedFieldSet ,
22722281 {
22732282 errors : undefined ,
2283+ completed : false ,
22742284 deferUsageSet,
22752285 } ,
22762286 deferMap ,
@@ -2330,6 +2340,7 @@ function executeExecutionGroup(
23302340 deferMap ,
23312341 ) ;
23322342 } catch ( error ) {
2343+ incrementalContext . completed = true ;
23332344 return {
23342345 pendingExecutionGroup,
23352346 path : pathToArray ( path ) ,
@@ -2339,21 +2350,27 @@ function executeExecutionGroup(
23392350
23402351 if ( isPromise ( result ) ) {
23412352 return result . then (
2342- ( resolved ) =>
2343- buildCompletedExecutionGroup (
2353+ ( resolved ) => {
2354+ incrementalContext . completed = true ;
2355+ return buildCompletedExecutionGroup (
23442356 incrementalContext . errors ,
23452357 pendingExecutionGroup ,
23462358 path ,
23472359 resolved ,
2348- ) ,
2349- ( error : unknown ) => ( {
2350- pendingExecutionGroup,
2351- path : pathToArray ( path ) ,
2352- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2353- } ) ,
2360+ ) ;
2361+ } ,
2362+ ( error : unknown ) => {
2363+ incrementalContext . completed = true ;
2364+ return {
2365+ pendingExecutionGroup,
2366+ path : pathToArray ( path ) ,
2367+ errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2368+ } ;
2369+ } ,
23542370 ) ;
23552371 }
23562372
2373+ incrementalContext . completed = true ;
23572374 return buildCompletedExecutionGroup (
23582375 incrementalContext . errors ,
23592376 pendingExecutionGroup ,
@@ -2408,7 +2425,7 @@ function buildSyncStreamItemQueue(
24082425 initialPath ,
24092426 initialItem ,
24102427 exeContext ,
2411- { errors : undefined } ,
2428+ { errors : undefined , completed : false } ,
24122429 fieldDetailsList ,
24132430 info ,
24142431 itemType ,
@@ -2439,7 +2456,7 @@ function buildSyncStreamItemQueue(
24392456 itemPath ,
24402457 value ,
24412458 exeContext ,
2442- { errors : undefined } ,
2459+ { errors : undefined , completed : false } ,
24432460 fieldDetailsList ,
24442461 info ,
24452462 itemType ,
@@ -2531,7 +2548,7 @@ async function getNextAsyncStreamItemResult(
25312548 itemPath ,
25322549 iteration . value ,
25332550 exeContext ,
2534- { errors : undefined } ,
2551+ { errors : undefined , completed : false } ,
25352552 fieldDetailsList ,
25362553 info ,
25372554 itemType ,
@@ -2578,11 +2595,16 @@ function completeStreamItem(
25782595 incrementalContext ,
25792596 new Map ( ) ,
25802597 ) . then (
2581- ( resolvedItem ) =>
2582- buildStreamItemResult ( incrementalContext . errors , resolvedItem ) ,
2583- ( error : unknown ) => ( {
2584- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2585- } ) ,
2598+ ( resolvedItem ) => {
2599+ incrementalContext . completed = true ;
2600+ return buildStreamItemResult ( incrementalContext . errors , resolvedItem ) ;
2601+ } ,
2602+ ( error : unknown ) => {
2603+ incrementalContext . completed = true ;
2604+ return {
2605+ errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2606+ } ;
2607+ } ,
25862608 ) ;
25872609 }
25882610
@@ -2611,6 +2633,7 @@ function completeStreamItem(
26112633 result = { rawResult : null , incrementalDataRecords : undefined } ;
26122634 }
26132635 } catch ( error ) {
2636+ incrementalContext . completed = true ;
26142637 return {
26152638 errors : withError ( incrementalContext . errors , error ) ,
26162639 } ;
@@ -2630,14 +2653,20 @@ function completeStreamItem(
26302653 return { rawResult : null , incrementalDataRecords : undefined } ;
26312654 } )
26322655 . then (
2633- ( resolvedItem ) =>
2634- buildStreamItemResult ( incrementalContext . errors , resolvedItem ) ,
2635- ( error : unknown ) => ( {
2636- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2637- } ) ,
2656+ ( resolvedItem ) => {
2657+ incrementalContext . completed = true ;
2658+ return buildStreamItemResult ( incrementalContext . errors , resolvedItem ) ;
2659+ } ,
2660+ ( error : unknown ) => {
2661+ incrementalContext . completed = true ;
2662+ return {
2663+ errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2664+ } ;
2665+ } ,
26382666 ) ;
26392667 }
26402668
2669+ incrementalContext . completed = true ;
26412670 return buildStreamItemResult ( incrementalContext . errors , result ) ;
26422671}
26432672
0 commit comments