@@ -469,6 +469,89 @@ describe('Abort Signal', () => {
469469 await expect ( next$ ) . rejects . toThrow ( 'This operation was aborted' ) ;
470470 expect ( bResolverGotInvoked ) . toBe ( false ) ;
471471 } ) ;
472+ it ( 'stops pending stream execution for never-returning incremental delivery (@defer)' , async ( ) => {
473+ const aResolverGotInvokedD = createDeferred ( ) ;
474+ const requestGotCancelledD = createDeferred ( ) ;
475+ let bResolverGotInvoked = false ;
476+
477+ const schema = makeExecutableSchema ( {
478+ typeDefs : /* GraphQL */ `
479+ type Query {
480+ root: A!
481+ }
482+ type A {
483+ a: B!
484+ }
485+ type B {
486+ b: String
487+ }
488+ ` ,
489+ resolvers : {
490+ Query : {
491+ async root ( ) {
492+ return { } ;
493+ } ,
494+ } ,
495+ A : {
496+ async a ( ) {
497+ aResolverGotInvokedD . resolve ( ) ;
498+ await requestGotCancelledD . promise ;
499+ return { } ;
500+ } ,
501+ } ,
502+ B : {
503+ b ( ) {
504+ bResolverGotInvoked = true ;
505+ return new Promise ( ( ) => { } ) ;
506+ } ,
507+ } ,
508+ } ,
509+ } ) ;
510+ const controller = new AbortController ( ) ;
511+ const result = await normalizedExecutor ( {
512+ schema,
513+ document : parse ( /* GraphQL */ `
514+ query {
515+ root {
516+ ... @defer {
517+ a {
518+ b
519+ }
520+ }
521+ }
522+ }
523+ ` ) ,
524+ signal : controller . signal ,
525+ } ) ;
526+
527+ if ( ! isAsyncIterable ( result ) ) {
528+ throw new Error ( 'Result is not an async iterable' ) ;
529+ }
530+
531+ const iterator = result [ Symbol . asyncIterator ] ( ) ;
532+ const next = await iterator . next ( ) ;
533+ expect ( next . value ) . toMatchInlineSnapshot ( `
534+ {
535+ "data": {
536+ "root": {},
537+ },
538+ "hasNext": true,
539+ "pending": [
540+ {
541+ "id": "0",
542+ "path": [
543+ "root",
544+ ],
545+ },
546+ ],
547+ }
548+ ` ) ;
549+ const next$ = iterator . next ( ) ;
550+ await aResolverGotInvokedD . promise ;
551+ controller . abort ( ) ;
552+ await expect ( next$ ) . rejects . toThrow ( 'This operation was aborted' ) ;
553+ expect ( bResolverGotInvoked ) . toBe ( false ) ;
554+ } ) ;
472555 it ( 'stops promise execution' , async ( ) => {
473556 const controller = new AbortController ( ) ;
474557 const d = createDeferred ( ) ;
0 commit comments