@@ -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 ) } } ,
@@ -232,7 +249,8 @@ describe('Execute: Handles inputs', () => {
232
249
locations : [ { line : 2 , column : 17 } ] ,
233
250
message :
234
251
'Variable "$input" expected value of type "TestInputObject" but ' +
235
- 'got: {"a":"foo","b":"bar","c":null}.'
252
+ 'got: {"a":"foo","b":"bar","c":null}. ' +
253
+ 'In field c: Expected non-null value.'
236
254
} ) ;
237
255
} ) ;
238
256
@@ -250,7 +268,7 @@ describe('Execute: Handles inputs', () => {
250
268
locations : [ { line : 2 , column : 17 } ] ,
251
269
message :
252
270
'Variable "$input" expected value of type "TestInputObject" but ' +
253
- 'got: "foo bar".'
271
+ 'got: "foo bar". Not an object. '
254
272
} ) ;
255
273
} ) ;
256
274
@@ -268,10 +286,37 @@ describe('Execute: Handles inputs', () => {
268
286
locations : [ { line : 2 , column : 17 } ] ,
269
287
message :
270
288
'Variable "$input" expected value of type "TestInputObject" but ' +
271
- 'got: {"a":"foo","b":"bar"}.'
289
+ 'got: {"a":"foo","b":"bar"}. In field c: Expected non-null value. '
272
290
} ) ;
273
291
} ) ;
274
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" expected value of type "TestNestedInputObject" but ' +
313
+ 'got: {"na":{"a":"foo"}}.' +
314
+ ' In field na: In field c: Expected non-null value.' +
315
+ ' In field nb: Expected non-null value.'
316
+ } ) ;
317
+
318
+ } ) ;
319
+
275
320
it ( 'errors on addition of unknown input field' , async ( ) => {
276
321
var params = { input : { a : 'foo' , b : 'bar' , c : 'baz' , d : 'dog' } } ;
277
322
@@ -643,7 +688,7 @@ describe('Execute: Handles inputs', () => {
643
688
locations : [ { line : 2 , column : 17 } ] ,
644
689
message :
645
690
'Variable "$input" expected value of type "[String!]" but got: ' +
646
- '["A",null,"B"].'
691
+ '["A",null,"B"]. In element #1: Expected non-null value. '
647
692
} ) ;
648
693
} ) ;
649
694
@@ -706,7 +751,7 @@ describe('Execute: Handles inputs', () => {
706
751
locations : [ { line : 2 , column : 17 } ] ,
707
752
message :
708
753
'Variable "$input" expected value of type "[String!]!" but got: ' +
709
- '["A",null,"B"].'
754
+ '["A",null,"B"]. In element #1: Expected non-null value. '
710
755
} ) ;
711
756
} ) ;
712
757
0 commit comments