@@ -56,6 +56,14 @@ var TestInputObject = new GraphQLInputObjectType({
56
56
}
57
57
} ) ;
58
58
59
+ var TestNestedInputObject = new GraphQLInputObjectType ( {
60
+ name : 'TestNestedInputObject' ,
61
+ fields : {
62
+ na : { type : new GraphQLNonNull ( TestInputObject ) } ,
63
+ nb : { type : new GraphQLNonNull ( GraphQLString ) } ,
64
+ } ,
65
+ } ) ;
66
+
59
67
var TestType = new GraphQLObjectType ( {
60
68
name : 'TestType' ,
61
69
fields : {
@@ -79,6 +87,15 @@ var TestType = new GraphQLObjectType({
79
87
args : { input : { type : GraphQLString , defaultValue : 'Hello World' } } ,
80
88
resolve : ( _ , { input } ) => input && JSON . stringify ( input )
81
89
} ,
90
+ fieldWithNestedInputObject : {
91
+ type : GraphQLString ,
92
+ args : {
93
+ input : {
94
+ type : TestNestedInputObject , defaultValue : 'Hello World'
95
+ }
96
+ } ,
97
+ resolve : ( _ , { input } ) => input && JSON . stringify ( input )
98
+ } ,
82
99
list : {
83
100
type : GraphQLString ,
84
101
args : { input : { type : new GraphQLList ( GraphQLString ) } } ,
@@ -231,8 +248,9 @@ describe('Execute: Handles inputs', () => {
231
248
expect ( caughtError ) . to . containSubset ( {
232
249
locations : [ { line : 2 , column : 17 } ] ,
233
250
message :
234
- 'Variable "$input" expected value of type "TestInputObject" but ' +
235
- 'got: {"a":"foo","b":"bar","c":null}.'
251
+ 'Variable "$input" got invalid value ' +
252
+ '{"a":"foo","b":"bar","c":null}.' +
253
+ '\nIn field "c": Expected "String!", found null.'
236
254
} ) ;
237
255
} ) ;
238
256
@@ -249,8 +267,8 @@ describe('Execute: Handles inputs', () => {
249
267
expect ( caughtError ) . to . containSubset ( {
250
268
locations : [ { line : 2 , column : 17 } ] ,
251
269
message :
252
- 'Variable "$input" expected value of type "TestInputObject" but ' +
253
- 'got: "foo bar" .'
270
+ 'Variable "$input" got invalid value "foo bar". ' +
271
+ '\nExpected "TestInputObject", found not an object .'
254
272
} ) ;
255
273
} ) ;
256
274
@@ -267,9 +285,35 @@ describe('Execute: Handles inputs', () => {
267
285
expect ( caughtError ) . to . containSubset ( {
268
286
locations : [ { line : 2 , column : 17 } ] ,
269
287
message :
270
- 'Variable "$input" expected value of type "TestInputObject" but ' +
271
- 'got: {"a":"foo","b":"bar"}.'
288
+ 'Variable "$input" got invalid value {"a":"foo","b":"bar"}.' +
289
+ '\nIn field "c": Expected "String!", found null.'
290
+ } ) ;
291
+ } ) ;
292
+
293
+ it ( 'errors on deep nested errors and with many errors' , async ( ) => {
294
+ var nestedDoc = `
295
+ query q($input: TestNestedInputObject) {
296
+ fieldWithNestedObjectInput(input: $input)
297
+ }
298
+ ` ;
299
+ var nestedAst = parse ( nestedDoc ) ;
300
+ var params = { input : { na : { a : 'foo' } } } ;
301
+
302
+ var caughtError ;
303
+ try {
304
+ execute ( schema , nestedAst , null , params ) ;
305
+ } catch ( error ) {
306
+ caughtError = error ;
307
+ }
308
+
309
+ expect ( caughtError ) . to . containSubset ( {
310
+ locations : [ { line : 2 , column : 19 } ] ,
311
+ message :
312
+ 'Variable "$input" got invalid value {"na":{"a":"foo"}}.' +
313
+ '\nIn field "na": In field "c": Expected "String!", found null.' +
314
+ '\nIn field "nb": Expected "String!", found null.'
272
315
} ) ;
316
+
273
317
} ) ;
274
318
275
319
it ( 'errors on addition of unknown input field' , async ( ) => {
@@ -285,8 +329,10 @@ describe('Execute: Handles inputs', () => {
285
329
expect ( caughtError ) . to . containSubset ( {
286
330
locations : [ { line : 2 , column : 17 } ] ,
287
331
message :
288
- 'Variable "$input" expected value of type "TestInputObject" but ' +
289
- 'got: {"a":"foo","b":"bar","c":"baz","d":"dog"}.'
332
+ 'Variable "$input" got invalid value ' +
333
+ '{"a":"foo","b":"bar","c":"baz","d":"dog"}.' +
334
+ '\nIn field "d": Expected type "ComplexScalar", found "dog".'
335
+
290
336
} ) ;
291
337
} ) ;
292
338
@@ -642,8 +688,8 @@ describe('Execute: Handles inputs', () => {
642
688
expect ( caughtError ) . to . containSubset ( {
643
689
locations : [ { line : 2 , column : 17 } ] ,
644
690
message :
645
- 'Variable "$input" expected value of type "[String!]" but got: ' +
646
- '["A", null,"B"] .'
691
+ 'Variable "$input" got invalid value ["A",null,"B"]. ' +
692
+ '\nIn element #1: Expected "String!", found null.'
647
693
} ) ;
648
694
} ) ;
649
695
@@ -705,8 +751,8 @@ describe('Execute: Handles inputs', () => {
705
751
expect ( caughtError ) . to . containSubset ( {
706
752
locations : [ { line : 2 , column : 17 } ] ,
707
753
message :
708
- 'Variable "$input" expected value of type "[String!]!" but got: ' +
709
- '["A", null,"B"] .'
754
+ 'Variable "$input" got invalid value ["A",null,"B"]. ' +
755
+ '\nIn element #1: Expected "String!", found null.'
710
756
} ) ;
711
757
} ) ;
712
758
0 commit comments