@@ -324,9 +324,10 @@ describe('Type System: Objects', () => {
324
324
expect ( ( ) => objType . getFields ( ) ) . to . not . throw ( ) ;
325
325
} ) ;
326
326
327
- it ( 'rejects an Object type without name' , ( ) => {
328
- // @ts -expect-error
329
- expect ( ( ) => new GraphQLObjectType ( { } ) ) . to . throw ( 'Must provide name.' ) ;
327
+ it ( 'rejects an Object type with invalid name' , ( ) => {
328
+ expect (
329
+ ( ) => new GraphQLObjectType ( { name : 'bad-name' , fields : { } } ) ,
330
+ ) . to . throw ( 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ) ;
330
331
} ) ;
331
332
332
333
it ( 'rejects an Object type field with undefined config' , ( ) => {
@@ -353,6 +354,18 @@ describe('Type System: Objects', () => {
353
354
) ;
354
355
} ) ;
355
356
357
+ it ( 'rejects an Object type with incorrectly named fields' , ( ) => {
358
+ const objType = new GraphQLObjectType ( {
359
+ name : 'SomeObject' ,
360
+ fields : {
361
+ 'bad-name' : { type : ScalarType } ,
362
+ } ,
363
+ } ) ;
364
+ expect ( ( ) => objType . getFields ( ) ) . to . throw (
365
+ 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ,
366
+ ) ;
367
+ } ) ;
368
+
356
369
it ( 'rejects an Object type with a field function that returns incorrect type' , ( ) => {
357
370
const objType = new GraphQLObjectType ( {
358
371
name : 'SomeObject' ,
@@ -380,6 +393,23 @@ describe('Type System: Objects', () => {
380
393
) ;
381
394
} ) ;
382
395
396
+ it ( 'rejects an Object type with incorrectly named field args' , ( ) => {
397
+ const objType = new GraphQLObjectType ( {
398
+ name : 'SomeObject' ,
399
+ fields : {
400
+ badField : {
401
+ type : ScalarType ,
402
+ args : {
403
+ 'bad-name' : { type : ScalarType } ,
404
+ } ,
405
+ } ,
406
+ } ,
407
+ } ) ;
408
+ expect ( ( ) => objType . getFields ( ) ) . to . throw (
409
+ 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ,
410
+ ) ;
411
+ } ) ;
412
+
383
413
it ( 'rejects an Object type with incorrectly typed interfaces' , ( ) => {
384
414
const objType = new GraphQLObjectType ( {
385
415
name : 'SomeObject' ,
@@ -478,9 +508,10 @@ describe('Type System: Interfaces', () => {
478
508
expect ( implementing . getInterfaces ( ) ) . to . deep . equal ( [ InterfaceType ] ) ;
479
509
} ) ;
480
510
481
- it ( 'rejects an Interface type without name' , ( ) => {
482
- // @ts -expect-error
483
- expect ( ( ) => new GraphQLInterfaceType ( { } ) ) . to . throw ( 'Must provide name.' ) ;
511
+ it ( 'rejects an Interface type with invalid name' , ( ) => {
512
+ expect (
513
+ ( ) => new GraphQLInterfaceType ( { name : 'bad-name' , fields : { } } ) ,
514
+ ) . to . throw ( 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ) ;
484
515
} ) ;
485
516
486
517
it ( 'rejects an Interface type with incorrectly typed interfaces' , ( ) => {
@@ -559,9 +590,10 @@ describe('Type System: Unions', () => {
559
590
expect ( unionType . getTypes ( ) ) . to . deep . equal ( [ ] ) ;
560
591
} ) ;
561
592
562
- it ( 'rejects an Union type without name' , ( ) => {
563
- // @ts -expect-error
564
- expect ( ( ) => new GraphQLUnionType ( { } ) ) . to . throw ( 'Must provide name.' ) ;
593
+ it ( 'rejects an Union type with invalid name' , ( ) => {
594
+ expect (
595
+ ( ) => new GraphQLUnionType ( { name : 'bad-name' , types : [ ] } ) ,
596
+ ) . to . throw ( 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ) ;
565
597
} ) ;
566
598
567
599
it ( 'rejects an Union type with an incorrect type for resolveType' , ( ) => {
@@ -674,11 +706,10 @@ describe('Type System: Enums', () => {
674
706
expect ( enumType . getValue ( 'BAR' ) ) . has . property ( 'value' , 20 ) ;
675
707
} ) ;
676
708
677
- it ( 'rejects an Enum type without name' , ( ) => {
678
- // @ts -expect-error
679
- expect ( ( ) => new GraphQLEnumType ( { values : { } } ) ) . to . throw (
680
- 'Must provide name.' ,
681
- ) ;
709
+ it ( 'rejects an Enum type with invalid name' , ( ) => {
710
+ expect (
711
+ ( ) => new GraphQLEnumType ( { name : 'bad-name' , values : { } } ) ,
712
+ ) . to . throw ( 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ) ;
682
713
} ) ;
683
714
684
715
it ( 'rejects an Enum type with incorrectly typed values' , ( ) => {
@@ -692,6 +723,18 @@ describe('Type System: Enums', () => {
692
723
) . to . throw ( 'SomeEnum values must be an object with value names as keys.' ) ;
693
724
} ) ;
694
725
726
+ it ( 'rejects an Enum type with incorrectly named values' , ( ) => {
727
+ expect (
728
+ ( ) =>
729
+ new GraphQLEnumType ( {
730
+ name : 'SomeEnum' ,
731
+ values : {
732
+ 'bad-name' : { } ,
733
+ } ,
734
+ } ) ,
735
+ ) . to . throw ( 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ) ;
736
+ } ) ;
737
+
695
738
it ( 'rejects an Enum type with missing value definition' , ( ) => {
696
739
expect (
697
740
( ) =>
@@ -761,10 +804,11 @@ describe('Type System: Input Objects', () => {
761
804
} ) ;
762
805
} ) ;
763
806
764
- it ( 'rejects an Input Object type without name' , ( ) => {
765
- // @ts -expect-error
766
- expect ( ( ) => new GraphQLInputObjectType ( { } ) ) . to . throw (
767
- 'Must provide name.' ,
807
+ it ( 'rejects an Input Object type with invalid name' , ( ) => {
808
+ expect (
809
+ ( ) => new GraphQLInputObjectType ( { name : 'bad-name' , fields : { } } ) ,
810
+ ) . to . throw (
811
+ 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ,
768
812
) ;
769
813
} ) ;
770
814
@@ -789,6 +833,18 @@ describe('Type System: Input Objects', () => {
789
833
'SomeInputObject fields must be an object with field names as keys or a function which returns such an object.' ,
790
834
) ;
791
835
} ) ;
836
+
837
+ it ( 'rejects an Input Object type with incorrectly named fields' , ( ) => {
838
+ const inputObjType = new GraphQLInputObjectType ( {
839
+ name : 'SomeInputObject' ,
840
+ fields : {
841
+ 'bad-name' : { type : ScalarType } ,
842
+ } ,
843
+ } ) ;
844
+ expect ( ( ) => inputObjType . getFields ( ) ) . to . throw (
845
+ 'Names must only contain [_a-zA-Z0-9] but "bad-name" does not.' ,
846
+ ) ;
847
+ } ) ;
792
848
} ) ;
793
849
794
850
describe ( 'Input Object fields must not have resolvers' , ( ) => {
0 commit comments