@@ -201,6 +201,120 @@ describe('Validate: Defer/Stream directive on valid operations', () => {
201201 } ,
202202 ] ) ;
203203 } ) ;
204+ it ( 'Defer fragment spread with @skip directive' , ( ) => {
205+ expectValid ( `
206+ subscription MySubscription {
207+ subscriptionField {
208+ ...myFragment @skip @defer
209+ }
210+ }
211+ fragment myFragment on Message {
212+ body
213+ }
214+ ` ) ;
215+ } ) ;
216+ it ( 'Defer fragment spread with @skip(if: true) directive' , ( ) => {
217+ expectValid ( `
218+ subscription MySubscription {
219+ subscriptionField {
220+ ...myFragment @skip(if: true) @defer
221+ }
222+ }
223+ fragment myFragment on Message {
224+ body
225+ }
226+ ` ) ;
227+ } ) ;
228+ it ( 'Defer fragment spread with @skip(if: false) directive' , ( ) => {
229+ expectErrors ( `
230+ subscription MySubscription {
231+ subscriptionField {
232+ ...myFragment @skip(if: false) @defer
233+ }
234+ }
235+ fragment myFragment on Message {
236+ body
237+ }
238+ ` ) . toDeepEqual ( [
239+ {
240+ locations : [ { column : 42 , line : 4 } ] ,
241+ message :
242+ 'Defer directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.' ,
243+ } ,
244+ ] ) ;
245+ } ) ;
246+ it ( 'Defer fragment spread with @skip(if: $variable) directive' , ( ) => {
247+ expectValid ( `
248+ subscription MySubscription($variable: Boolean) {
249+ subscriptionField {
250+ ...myFragment @skip(if: $variable) @defer
251+ }
252+ }
253+ fragment myFragment on Message {
254+ body
255+ }
256+ ` ) ;
257+ } ) ;
258+ it ( 'Defer fragment spread with @include directive' , ( ) => {
259+ expectErrors ( `
260+ subscription MySubscription {
261+ subscriptionField {
262+ ...myFragment @include @defer
263+ }
264+ }
265+ fragment myFragment on Message {
266+ body
267+ }
268+ ` ) . toDeepEqual ( [
269+ {
270+ locations : [ { column : 34 , line : 4 } ] ,
271+ message :
272+ 'Defer directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.' ,
273+ } ,
274+ ] ) ;
275+ } ) ;
276+ it ( 'Defer fragment spread with @include(if: true) directive' , ( ) => {
277+ expectErrors ( `
278+ subscription MySubscription {
279+ subscriptionField {
280+ ...myFragment @include(if: true) @defer
281+ }
282+ }
283+ fragment myFragment on Message {
284+ body
285+ }
286+ ` ) . toDeepEqual ( [
287+ {
288+ locations : [ { column : 44 , line : 4 } ] ,
289+ message :
290+ 'Defer directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.' ,
291+ } ,
292+ ] ) ;
293+ } ) ;
294+ it ( 'Defer fragment spread with @include(if: false) directive' , ( ) => {
295+ expectValid ( `
296+ subscription MySubscription {
297+ subscriptionField {
298+ ...myFragment @include(if: false) @defer
299+ }
300+ }
301+ fragment myFragment on Message {
302+ body
303+ }
304+ ` ) ;
305+ } ) ;
306+ it ( 'Defer fragment spread with @include(if: $variable) directive' , ( ) => {
307+ expectValid ( `
308+ subscription MySubscription ($variable: Boolean) {
309+ subscriptionField {
310+ ...myFragment @include(if: $variable) @defer
311+ }
312+ }
313+ fragment myFragment on Message {
314+ body
315+ }
316+ ` ) ;
317+ } ) ;
204318 it ( 'Stream on query field' , ( ) => {
205319 expectValid ( `
206320 {
@@ -260,7 +374,10 @@ describe('Validate: Defer/Stream directive on valid operations', () => {
260374 {
261375 message :
262376 'Stream directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`.' ,
263- locations : [ { line : 8 , column : 18 } ] ,
377+ locations : [
378+ { line : 8 , column : 18 } ,
379+ { line : 4 , column : 11 } ,
380+ ] ,
264381 } ,
265382 ] ) ;
266383 } ) ;
@@ -302,7 +419,38 @@ describe('Validate: Defer/Stream directive on valid operations', () => {
302419 {
303420 message :
304421 'Stream directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`.' ,
305- locations : [ { line : 15 , column : 18 } ] ,
422+ locations : [
423+ { line : 15 , column : 18 } ,
424+ { line : 10 , column : 13 } ,
425+ ] ,
426+ } ,
427+ ] ) ;
428+ } ) ;
429+ it ( 'Stream on subscription in document with fragment used multiple times' , ( ) => {
430+ expectErrors ( `
431+ subscription MySubscription {
432+ subscriptionField {
433+ message {
434+ ...myOtherFragment
435+ ...myFragment
436+ }
437+ }
438+ }
439+ fragment myOtherFragment on Message {
440+ ...myFragment
441+ }
442+ fragment myFragment on Message {
443+ messages @stream
444+ }
445+ ` ) . toDeepEqual ( [
446+ {
447+ message :
448+ 'Stream directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`.' ,
449+ locations : [
450+ { line : 14 , column : 18 } ,
451+ { line : 11 , column : 9 } ,
452+ { line : 5 , column : 13 } ,
453+ ] ,
306454 } ,
307455 ] ) ;
308456 } ) ;
0 commit comments