@@ -26,6 +26,10 @@ const friendType = new GraphQLObjectType({
2626 fields : {
2727 id : { type : GraphQLID } ,
2828 name : { type : GraphQLString } ,
29+ promiseNonNullErrorField : {
30+ type : new GraphQLNonNull ( GraphQLString ) ,
31+ resolve : ( ) => Promise . resolve ( null ) ,
32+ } ,
2933 } ,
3034 name : 'Friend' ,
3135} ) ;
@@ -65,6 +69,12 @@ const heroType = new GraphQLObjectType({
6569 type : new GraphQLList ( friendType ) ,
6670 resolve : ( ) => friends ,
6771 } ,
72+ asyncFriends : {
73+ type : new GraphQLList ( friendType ) ,
74+ async * resolve ( ) {
75+ yield await Promise . resolve ( friends [ 0 ] ) ;
76+ } ,
77+ } ,
6878 } ,
6979 name : 'Hero' ,
7080} ) ;
@@ -657,6 +667,38 @@ describe('Execute: defer directive', () => {
657667 ] ) ;
658668 } ) ;
659669
670+ it ( 'Filters deferred payloads when a list item returned by an async iterable is nulled' , async ( ) => {
671+ const document = parse ( `
672+ query {
673+ hero {
674+ asyncFriends {
675+ promiseNonNullErrorField
676+ ...NameFragment @defer
677+ }
678+ }
679+ }
680+ fragment NameFragment on Friend {
681+ name
682+ }
683+ ` ) ;
684+ const result = await complete ( document ) ;
685+ expectJSON ( result ) . toDeepEqual ( {
686+ data : {
687+ hero : {
688+ asyncFriends : [ null ] ,
689+ } ,
690+ } ,
691+ errors : [
692+ {
693+ message :
694+ 'Cannot return null for non-nullable field Friend.promiseNonNullErrorField.' ,
695+ locations : [ { line : 5 , column : 11 } ] ,
696+ path : [ 'hero' , 'asyncFriends' , 0 , 'promiseNonNullErrorField' ] ,
697+ } ,
698+ ] ,
699+ } ) ;
700+ } ) ;
701+
660702 it ( 'original execute function throws error if anything is deferred and everything else is sync' , ( ) => {
661703 const doc = `
662704 query Deferred {
0 commit comments