@@ -30,7 +30,12 @@ function executeQuery(
30
30
rootValue : unknown ,
31
31
variableValues ?: { [ variable : string ] : unknown } ,
32
32
) : ExecutionResult | Promise < ExecutionResult > {
33
- return execute ( { schema, document : parse ( query ) , rootValue, variableValues } ) ;
33
+ return execute ( {
34
+ schema,
35
+ document : parse ( query , { experimentalFragmentArguments : true } ) ,
36
+ rootValue,
37
+ variableValues,
38
+ } ) ;
34
39
}
35
40
36
41
describe ( 'Execute: Handles OneOf Input Objects' , ( ) => {
@@ -134,6 +139,28 @@ describe('Execute: Handles OneOf Input Objects', () => {
134
139
} ) ;
135
140
} ) ;
136
141
142
+ it ( 'rejects a variable with a nulled key' , ( ) => {
143
+ const query = `
144
+ query ($input: TestInputObject!) {
145
+ test(input: $input) {
146
+ a
147
+ b
148
+ }
149
+ }
150
+ ` ;
151
+ const result = executeQuery ( query , rootValue , { input : { a : null } } ) ;
152
+
153
+ expectJSON ( result ) . toDeepEqual ( {
154
+ errors : [
155
+ {
156
+ message :
157
+ 'Variable "$input" got invalid value null at "input.a"; Field "a" must be non-null.' ,
158
+ locations : [ { line : 2 , column : 16 } ] ,
159
+ } ,
160
+ ] ,
161
+ } ) ;
162
+ } ) ;
163
+
137
164
it ( 'rejects a variable with multiple non-null keys' , ( ) => {
138
165
const query = `
139
166
query ($input: TestInputObject!) {
@@ -181,5 +208,123 @@ describe('Execute: Handles OneOf Input Objects', () => {
181
208
] ,
182
209
} ) ;
183
210
} ) ;
211
+
212
+ it ( 'errors with nulled variable for field' , ( ) => {
213
+ const query = `
214
+ query ($a: String) {
215
+ test(input: { a: $a }) {
216
+ a
217
+ b
218
+ }
219
+ }
220
+ ` ;
221
+ const result = executeQuery ( query , rootValue , { a : null } ) ;
222
+
223
+ expectJSON ( result ) . toDeepEqual ( {
224
+ data : {
225
+ test : null ,
226
+ } ,
227
+ errors : [
228
+ {
229
+ // A nullable variable in a oneOf field position would be caught at validation-time
230
+ // hence the vague error message here.
231
+ message :
232
+ 'Argument "input" of type "TestInputObject!" has invalid value { a: $a }.' ,
233
+ locations : [ { line : 3 , column : 23 } ] ,
234
+ path : [ 'test' ] ,
235
+ } ,
236
+ ] ,
237
+ } ) ;
238
+ } ) ;
239
+
240
+ it ( 'errors with missing variable for field' , ( ) => {
241
+ const query = `
242
+ query ($a: String) {
243
+ test(input: { a: $a }) {
244
+ a
245
+ b
246
+ }
247
+ }
248
+ ` ;
249
+ const result = executeQuery ( query , rootValue ) ;
250
+
251
+ expectJSON ( result ) . toDeepEqual ( {
252
+ data : {
253
+ test : null ,
254
+ } ,
255
+ errors : [
256
+ {
257
+ // A nullable variable in a oneOf field position would be caught at validation-time
258
+ // hence the vague error message here.
259
+ message :
260
+ 'Argument "input" of type "TestInputObject!" has invalid value { a: $a }.' ,
261
+ locations : [ { line : 3 , column : 23 } ] ,
262
+ path : [ 'test' ] ,
263
+ } ,
264
+ ] ,
265
+ } ) ;
266
+ } ) ;
267
+
268
+ it ( 'errors with nulled fragment variable for field' , ( ) => {
269
+ const query = `
270
+ query {
271
+ ...TestFragment(a: null)
272
+ }
273
+ fragment TestFragment($a: String) on Query {
274
+ test(input: { a: $a }) {
275
+ a
276
+ b
277
+ }
278
+ }
279
+ ` ;
280
+ const result = executeQuery ( query , rootValue , { a : null } ) ;
281
+
282
+ expectJSON ( result ) . toDeepEqual ( {
283
+ data : {
284
+ test : null ,
285
+ } ,
286
+ errors : [
287
+ {
288
+ // A nullable variable in a oneOf field position would be caught at validation-time
289
+ // hence the vague error message here.
290
+ message :
291
+ 'Argument "input" of type "TestInputObject!" has invalid value { a: $a }.' ,
292
+ locations : [ { line : 6 , column : 23 } ] ,
293
+ path : [ 'test' ] ,
294
+ } ,
295
+ ] ,
296
+ } ) ;
297
+ } ) ;
298
+
299
+ it ( 'errors with missing fragment variable for field' , ( ) => {
300
+ const query = `
301
+ query {
302
+ ...TestFragment
303
+ }
304
+ fragment TestFragment($a: String) on Query {
305
+ test(input: { a: $a }) {
306
+ a
307
+ b
308
+ }
309
+ }
310
+ ` ;
311
+ const result = executeQuery ( query , rootValue ) ;
312
+
313
+ expectJSON ( result ) . toDeepEqual ( {
314
+ data : {
315
+ test : null ,
316
+ } ,
317
+ errors : [
318
+ {
319
+ // A nullable variable in a oneOf field position would be caught at validation-time
320
+ // hence the vague error message here.
321
+ message :
322
+ 'Argument "input" of type "TestInputObject!" has invalid value { a: $a }.' ,
323
+ locations : [ { line : 6 , column : 23 } ] ,
324
+ path : [ 'test' ] ,
325
+ } ,
326
+ ] ,
327
+ } ) ;
328
+ } ) ;
184
329
} ) ;
185
330
} ) ;
0 commit comments