@@ -2,6 +2,7 @@ import { expect } from 'chai';
22import { describe , it } from 'mocha' ;
33
44import { expectJSON } from '../../__testUtils__/expectJSON.js' ;
5+ import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js' ;
56
67import type { PromiseOrValue } from '../../jsutils/PromiseOrValue.js' ;
78
@@ -526,6 +527,68 @@ describe('Execute: handles non-nullable types', () => {
526527 } ) ;
527528 } ) ;
528529
530+ describe ( 'cancellation with null bubbling' , ( ) => {
531+ function nestedPromise ( n : number ) : string {
532+ return n > 0 ? `promiseNest { ${ nestedPromise ( n - 1 ) } }` : 'promise' ;
533+ }
534+
535+ it ( 'returns an single error without cancellation' , async ( ) => {
536+ const query = `
537+ {
538+ promiseNonNull,
539+ ${ nestedPromise ( 4 ) }
540+ }
541+ ` ;
542+
543+ const result = await executeQuery ( query , throwingData ) ;
544+ expectJSON ( result ) . toDeepEqual ( {
545+ data : null ,
546+ errors : [
547+ // does not include syncNullError because result returns prior to it being added
548+ {
549+ message : 'promiseNonNull' ,
550+ path : [ 'promiseNonNull' ] ,
551+ locations : [ { line : 3 , column : 11 } ] ,
552+ } ,
553+ ] ,
554+ } ) ;
555+ } ) ;
556+
557+ it ( 'stops running despite error' , async ( ) => {
558+ const query = `
559+ {
560+ promiseNonNull,
561+ ${ nestedPromise ( 10 ) }
562+ }
563+ ` ;
564+
565+ let counter = 0 ;
566+ const rootValue = {
567+ ...throwingData ,
568+ promiseNest ( ) {
569+ return new Promise ( ( resolve ) => {
570+ counter ++ ;
571+ resolve ( rootValue ) ;
572+ } ) ;
573+ } ,
574+ } ;
575+ const result = await executeQuery ( query , rootValue ) ;
576+ expectJSON ( result ) . toDeepEqual ( {
577+ data : null ,
578+ errors : [
579+ {
580+ message : 'promiseNonNull' ,
581+ path : [ 'promiseNonNull' ] ,
582+ locations : [ { line : 3 , column : 11 } ] ,
583+ } ,
584+ ] ,
585+ } ) ;
586+ const counterAtExecutionEnd = counter ;
587+ await resolveOnNextTick ( ) ;
588+ expect ( counter ) . to . equal ( counterAtExecutionEnd ) ;
589+ } ) ;
590+ } ) ;
591+
529592 describe ( 'Handles non-null argument' , ( ) => {
530593 const schemaWithNonNullArg = new GraphQLSchema ( {
531594 query : new GraphQLObjectType ( {
0 commit comments