@@ -14,6 +14,7 @@ import {
14
14
GraphQLID ,
15
15
GraphQLInt ,
16
16
GraphQLFloat ,
17
+ GraphQLList ,
17
18
GraphQLString ,
18
19
GraphQLEnumType ,
19
20
GraphQLInputObjectType ,
@@ -239,14 +240,14 @@ describe('coerceValue', () => {
239
240
expectValue ( result ) . to . deep . equal ( { foo : 123 } ) ;
240
241
} ) ;
241
242
242
- it ( 'returns no error for a non-object type' , ( ) => {
243
+ it ( 'returns an error for a non-object type' , ( ) => {
243
244
const result = coerceValue ( 123 , TestInputObject ) ;
244
245
expectErrors ( result ) . to . deep . equal ( [
245
246
'Expected type TestInputObject to be an object.' ,
246
247
] ) ;
247
248
} ) ;
248
249
249
- it ( 'returns no error for an invalid field' , ( ) => {
250
+ it ( 'returns an error for an invalid field' , ( ) => {
250
251
const result = coerceValue ( { foo : 'abc' } , TestInputObject ) ;
251
252
expectErrors ( result ) . to . deep . equal ( [
252
253
'Expected type Int at value.foo; Int cannot represent non-integer value: "abc"' ,
@@ -285,4 +286,60 @@ describe('coerceValue', () => {
285
286
] ) ;
286
287
} ) ;
287
288
} ) ;
289
+
290
+ describe ( 'for GraphQLList' , ( ) => {
291
+ const TestList = GraphQLList ( GraphQLInt ) ;
292
+
293
+ it ( 'returns no error for a valid input' , ( ) => {
294
+ const result = coerceValue ( [ 1 , 2 , 3 ] , TestList ) ;
295
+ expectValue ( result ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
296
+ } ) ;
297
+
298
+ it ( 'returns an error for an invalid input' , ( ) => {
299
+ const result = coerceValue ( [ 1 , 'b' , true ] , TestList ) ;
300
+ expectErrors ( result ) . to . deep . equal ( [
301
+ 'Expected type Int at value[1]; Int cannot represent non-integer value: "b"' ,
302
+ 'Expected type Int at value[2]; Int cannot represent non-integer value: true' ,
303
+ ] ) ;
304
+ } ) ;
305
+
306
+ it ( 'returns a list for a non-list value' , ( ) => {
307
+ const result = coerceValue ( 42 , TestList ) ;
308
+ expectValue ( result ) . to . deep . equal ( [ 42 ] ) ;
309
+ } ) ;
310
+
311
+ it ( 'returns null for a null value' , ( ) => {
312
+ const result = coerceValue ( null , TestList ) ;
313
+ expectValue ( result ) . to . deep . equal ( null ) ;
314
+ } ) ;
315
+ } ) ;
316
+
317
+ describe ( 'for nested GraphQLList' , ( ) => {
318
+ const TestNestedList = GraphQLList ( GraphQLList ( GraphQLInt ) ) ;
319
+
320
+ it ( 'returns no error for a valid input' , ( ) => {
321
+ const result = coerceValue ( [ [ 1 ] , [ 2 , 3 ] ] , TestNestedList ) ;
322
+ expectValue ( result ) . to . deep . equal ( [ [ 1 ] , [ 2 , 3 ] ] ) ;
323
+ } ) ;
324
+
325
+ it ( 'returns a list for a non-list value' , ( ) => {
326
+ const result = coerceValue ( 42 , TestNestedList ) ;
327
+ expectValue ( result ) . to . deep . equal ( [ [ 42 ] ] ) ;
328
+ } ) ;
329
+
330
+ it ( 'returns null for a null value' , ( ) => {
331
+ const result = coerceValue ( null , TestNestedList ) ;
332
+ expectValue ( result ) . to . deep . equal ( null ) ;
333
+ } ) ;
334
+
335
+ it ( 'returns nested lists for nested non-list values' , ( ) => {
336
+ const result = coerceValue ( [ 1 , 2 , 3 ] , TestNestedList ) ;
337
+ expectValue ( result ) . to . deep . equal ( [ [ 1 ] , [ 2 ] , [ 3 ] ] ) ;
338
+ } ) ;
339
+
340
+ it ( 'returns nested null for nested null values' , ( ) => {
341
+ const result = coerceValue ( [ 42 , [ null ] , null ] , TestNestedList ) ;
342
+ expectValue ( result ) . to . deep . equal ( [ [ 42 ] , [ null ] , null ] ) ;
343
+ } ) ;
344
+ } ) ;
288
345
} ) ;
0 commit comments