@@ -296,6 +296,17 @@ describe('Type System: Objects must have fields', () => {
296
296
) ;
297
297
} ) ;
298
298
299
+ it ( 'rejects an Object type with incorrectly named fields' , ( ) => {
300
+ expect (
301
+ ( ) => schemaWithFieldType ( new GraphQLObjectType ( {
302
+ name : 'SomeObject' ,
303
+ fields : { 'bad-name-with-dashes' : { type : GraphQLString } }
304
+ } ) )
305
+ ) . to . throw (
306
+ 'Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "bad-name-with-dashes" does not.'
307
+ ) ;
308
+ } ) ;
309
+
299
310
it ( 'rejects an Object type with incorrectly typed fields' , ( ) => {
300
311
expect (
301
312
( ) => schemaWithFieldType ( new GraphQLObjectType ( {
@@ -353,6 +364,47 @@ describe('Type System: Objects must have fields', () => {
353
364
} ) ;
354
365
355
366
367
+ describe ( 'Type System: Fields args must be properly named' , ( ) => {
368
+
369
+ it ( 'accepts field args with valid names' , ( ) => {
370
+ expect (
371
+ ( ) => schemaWithFieldType ( new GraphQLObjectType ( {
372
+ name : 'SomeObject' ,
373
+ fields : {
374
+ goodField : {
375
+ type : GraphQLString ,
376
+ args : {
377
+ goodArg : { type : GraphQLString }
378
+ }
379
+ }
380
+ }
381
+ } ) )
382
+ ) . not . to . throw ( ) ;
383
+ } ) ;
384
+
385
+ it ( 'rejects field arg with invalid names' , ( ) => {
386
+ expect (
387
+ ( ) => {
388
+ var QueryType = new GraphQLObjectType ( {
389
+ name : 'SomeObject' ,
390
+ fields : {
391
+ badField : {
392
+ type : GraphQLString ,
393
+ args : {
394
+ 'bad-name-with-dashes' : { type : GraphQLString }
395
+ }
396
+ }
397
+ }
398
+ } ) ;
399
+ return new GraphQLSchema ( { query : QueryType } ) ;
400
+ } ) . to . throw (
401
+ 'Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "bad-name-with-dashes" does not.'
402
+ ) ;
403
+ } ) ;
404
+
405
+ } ) ;
406
+
407
+
356
408
describe ( 'Type System: Fields args must be objects' , ( ) => {
357
409
358
410
it ( 'accepts an Object type with field args' , ( ) => {
0 commit comments