@@ -46,6 +46,39 @@ describe('Star Wars Query Stream Tests', () => {
46
46
} ,
47
47
} ) ;
48
48
} ) ;
49
+ it ( 'Can disable @stream using if argument' , async ( ) => {
50
+ const query = `
51
+ query HeroFriendsQuery {
52
+ hero {
53
+ friends @stream(initial_count: 0, label: "HeroFriends", if: false) {
54
+ id
55
+ name
56
+ }
57
+ }
58
+ }
59
+ ` ;
60
+ const result = await graphql ( StarWarsSchemaDeferStreamEnabled , query ) ;
61
+ expect ( result ) . to . deep . equal ( {
62
+ data : {
63
+ hero : {
64
+ friends : [
65
+ {
66
+ id : '1000' ,
67
+ name : 'Luke Skywalker' ,
68
+ } ,
69
+ {
70
+ id : '1002' ,
71
+ name : 'Han Solo' ,
72
+ } ,
73
+ {
74
+ id : '1003' ,
75
+ name : 'Leia Organa' ,
76
+ } ,
77
+ ] ,
78
+ } ,
79
+ } ,
80
+ } ) ;
81
+ } ) ;
49
82
} ) ;
50
83
51
84
describe ( 'Basic Queries' , ( ) => {
@@ -97,84 +130,83 @@ describe('Star Wars Query Stream Tests', () => {
97
130
} ,
98
131
} ) ;
99
132
} ) ;
100
- } ) ;
101
-
102
- it ( 'Can @stream multiple selections on the same field' , async ( ) => {
103
- const query = `
104
- query HeroFriendsQuery {
105
- hero {
106
- friends {
107
- id
133
+ it ( 'Can @stream multiple selections on the same field' , async ( ) => {
134
+ const query = `
135
+ query HeroFriendsQuery {
136
+ hero {
137
+ friends {
138
+ id
139
+ }
140
+ ...FriendsName
141
+ ...FriendsAppearsIn
108
142
}
109
- ...FriendsName
110
- ...FriendsAppearsIn
111
143
}
112
- }
113
- fragment FriendsName on Character {
114
- friends @stream(label: "nameLabel", initial_count: 1) {
115
- name
144
+ fragment FriendsName on Character {
145
+ friends @stream(label: "nameLabel", initial_count: 1) {
146
+ name
147
+ }
116
148
}
117
- }
118
- fragment FriendsAppearsIn on Character {
119
- friends @stream(label: "appearsInLabel", initial_count: 2) {
120
- appearsIn
149
+ fragment FriendsAppearsIn on Character {
150
+ friends @stream(label: "appearsInLabel", initial_count: 2) {
151
+ appearsIn
152
+ }
121
153
}
122
- }
123
- ` ;
124
- const result = await graphql ( StarWarsSchemaDeferStreamEnabled , query ) ;
125
- const { patches : patchesIterable , ... initial } = result ;
126
- expect ( initial ) . to . deep . equal ( {
127
- data : {
128
- hero : {
129
- friends : [
130
- {
131
- id : '1000' ,
132
- appearsIn : [ 'NEW_HOPE' , 'EMPIRE' , 'JEDI' ] ,
133
- name : 'Luke Skywalker' ,
134
- } ,
135
- {
136
- id : '1002' ,
137
- appearsIn : [ 'NEW_HOPE' , 'EMPIRE' , 'JEDI' ] ,
138
- } ,
139
- {
140
- id : '1003' ,
141
- } ,
142
- ] ,
154
+ ` ;
155
+ const result = await graphql ( StarWarsSchemaDeferStreamEnabled , query ) ;
156
+ const { patches : patchesIterable , ... initial } = result ;
157
+ expect ( initial ) . to . deep . equal ( {
158
+ data : {
159
+ hero : {
160
+ friends : [
161
+ {
162
+ id : '1000' ,
163
+ appearsIn : [ 'NEW_HOPE' , 'EMPIRE' , 'JEDI' ] ,
164
+ name : 'Luke Skywalker' ,
165
+ } ,
166
+ {
167
+ id : '1002' ,
168
+ appearsIn : [ 'NEW_HOPE' , 'EMPIRE' , 'JEDI' ] ,
169
+ } ,
170
+ {
171
+ id : '1003' ,
172
+ } ,
173
+ ] ,
174
+ } ,
143
175
} ,
144
- } ,
145
- } ) ;
176
+ } ) ;
146
177
147
- const patches = [ ] ;
178
+ const patches = [ ] ;
148
179
149
- if ( patchesIterable ) {
150
- await forAwaitEach ( patchesIterable , patch => {
151
- patches . push ( patch ) ;
152
- } ) ;
153
- }
180
+ if ( patchesIterable ) {
181
+ await forAwaitEach ( patchesIterable , patch => {
182
+ patches . push ( patch ) ;
183
+ } ) ;
184
+ }
154
185
155
- expect ( patches ) . to . have . lengthOf ( 3 ) ;
156
- expect ( patches [ 0 ] ) . to . deep . equal ( {
157
- data : {
158
- name : 'Han Solo' ,
159
- } ,
160
- path : [ 'hero' , 'friends' , 1 ] ,
161
- label : 'nameLabel' ,
162
- } ) ;
186
+ expect ( patches ) . to . have . lengthOf ( 3 ) ;
187
+ expect ( patches [ 0 ] ) . to . deep . equal ( {
188
+ data : {
189
+ name : 'Han Solo' ,
190
+ } ,
191
+ path : [ 'hero' , 'friends' , 1 ] ,
192
+ label : 'nameLabel' ,
193
+ } ) ;
163
194
164
- expect ( patches [ 1 ] ) . to . deep . equal ( {
165
- data : {
166
- name : 'Leia Organa' ,
167
- } ,
168
- path : [ 'hero' , 'friends' , 2 ] ,
169
- label : 'nameLabel' ,
170
- } ) ;
195
+ expect ( patches [ 1 ] ) . to . deep . equal ( {
196
+ data : {
197
+ name : 'Leia Organa' ,
198
+ } ,
199
+ path : [ 'hero' , 'friends' , 2 ] ,
200
+ label : 'nameLabel' ,
201
+ } ) ;
171
202
172
- expect ( patches [ 2 ] ) . to . deep . equal ( {
173
- data : {
174
- appearsIn : [ 'NEW_HOPE' , 'EMPIRE' , 'JEDI' ] ,
175
- } ,
176
- path : [ 'hero' , 'friends' , 2 ] ,
177
- label : 'appearsInLabel' ,
203
+ expect ( patches [ 2 ] ) . to . deep . equal ( {
204
+ data : {
205
+ appearsIn : [ 'NEW_HOPE' , 'EMPIRE' , 'JEDI' ] ,
206
+ } ,
207
+ path : [ 'hero' , 'friends' , 2 ] ,
208
+ label : 'appearsInLabel' ,
209
+ } ) ;
178
210
} ) ;
179
211
} ) ;
180
212
} ) ;
0 commit comments