@@ -26,6 +26,10 @@ const friendType = new GraphQLObjectType({
26
26
fields : {
27
27
id : { type : GraphQLID } ,
28
28
name : { type : GraphQLString } ,
29
+ promiseNonNullErrorField : {
30
+ type : new GraphQLNonNull ( GraphQLString ) ,
31
+ resolve : ( ) => Promise . resolve ( null ) ,
32
+ } ,
29
33
} ,
30
34
name : 'Friend' ,
31
35
} ) ;
@@ -65,6 +69,12 @@ const heroType = new GraphQLObjectType({
65
69
type : new GraphQLList ( friendType ) ,
66
70
resolve : ( ) => friends ,
67
71
} ,
72
+ asyncFriends : {
73
+ type : new GraphQLList ( friendType ) ,
74
+ async * resolve ( ) {
75
+ yield await Promise . resolve ( friends [ 0 ] ) ;
76
+ } ,
77
+ } ,
68
78
} ,
69
79
name : 'Hero' ,
70
80
} ) ;
@@ -657,6 +667,38 @@ describe('Execute: defer directive', () => {
657
667
] ) ;
658
668
} ) ;
659
669
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
+
660
702
it ( 'original execute function throws error if anything is deferred and everything else is sync' , ( ) => {
661
703
const doc = `
662
704
query Deferred {
0 commit comments