@@ -5,11 +5,6 @@ const { canUseIncrementalExecution } = require('../lib/util')
55
66if ( canUseIncrementalExecution ) {
77 const schema = `
8- directive @defer(
9- if: Boolean! = true
10- label: String
11- ) on FRAGMENT_SPREAD | INLINE_FRAGMENT
12-
138 type Query {
149 allProducts: [Product!]!
1510 }
@@ -70,10 +65,37 @@ if (canUseIncrementalExecution) {
7065 'multipart/mixed; deferSpec=12345'
7166 ]
7267
68+ test ( 'errors with @defer when opts.defer is not true' , async t => {
69+ const app = Fastify ( )
70+ await app . register ( mercurius , { schema, resolvers, graphiql : true } )
71+
72+ const res = await app . inject ( {
73+ method : 'POST' ,
74+ url : '/graphql' ,
75+ headers : {
76+ 'content-type' : 'application/json'
77+ } ,
78+ body : JSON . stringify ( { query } )
79+ } )
80+
81+ t . match ( res , {
82+ statusCode : 400 ,
83+ body : JSON . stringify ( {
84+ data : null ,
85+ errors : [ {
86+ message : 'Unknown directive "@defer".' , locations : [ { line : 5 , column : 25 } ]
87+ } ]
88+ } )
89+ } )
90+
91+ await app . close ( )
92+ t . end ( )
93+ } )
94+
7395 for ( const accept of wrongAcceptValues ) {
7496 test ( 'errors with @defer when used with wrong "accept" header' , async t => {
7597 const app = Fastify ( )
76- await app . register ( mercurius , { schema, resolvers, graphiql : true } )
98+ await app . register ( mercurius , { schema, resolvers, graphiql : true , defer : true } )
7799
78100 const res = await app . inject ( {
79101 method : 'POST' ,
@@ -109,7 +131,7 @@ if (canUseIncrementalExecution) {
109131 for ( const accept of correctAcceptValues ) {
110132 test ( 'works with @defer when used with correct "accept" header' , async t => {
111133 const app = Fastify ( )
112- await app . register ( mercurius , { schema, resolvers, graphiql : true } )
134+ await app . register ( mercurius , { schema, resolvers, graphiql : true , defer : true } )
113135
114136 const res = await app . inject ( {
115137 method : 'POST' ,
0 commit comments