@@ -562,23 +562,33 @@ describe('Type System: Union types must be valid', () => {
562
562
} ) ;
563
563
564
564
it ( 'rejects a Union type with empty types' , ( ) => {
565
- const schema = buildSchema ( `
565
+ let schema = buildSchema ( `
566
566
type Query {
567
567
test: BadUnion
568
568
}
569
569
570
570
union BadUnion
571
571
` ) ;
572
+
573
+ schema = extendSchema (
574
+ schema ,
575
+ parse ( `
576
+ directive @test on UNION
577
+
578
+ extend union BadUnion @test
579
+ ` ) ,
580
+ ) ;
581
+
572
582
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
573
583
{
574
584
message : 'Union type BadUnion must define one or more member types.' ,
575
- locations : [ { line : 6 , column : 7 } ] ,
585
+ locations : [ { line : 6 , column : 7 } , { line : 4 , column : 9 } ] ,
576
586
} ,
577
587
] ) ;
578
588
} ) ;
579
589
580
590
it ( 'rejects a Union type with duplicated member type' , ( ) => {
581
- const schema = buildSchema ( `
591
+ let schema = buildSchema ( `
582
592
type Query {
583
593
test: BadUnion
584
594
}
@@ -596,16 +606,30 @@ describe('Type System: Union types must be valid', () => {
596
606
| TypeB
597
607
| TypeA
598
608
` ) ;
609
+
599
610
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
600
611
{
601
612
message : 'Union type BadUnion can only include type TypeA once.' ,
602
613
locations : [ { line : 15 , column : 11 } , { line : 17 , column : 11 } ] ,
603
614
} ,
604
615
] ) ;
616
+
617
+ schema = extendSchema ( schema , parse ( 'extend union BadUnion = TypeB' ) ) ;
618
+
619
+ expect ( validateSchema ( schema ) ) . to . deep . equal ( [
620
+ {
621
+ message : 'Union type BadUnion can only include type TypeA once.' ,
622
+ locations : [ { line : 15 , column : 11 } , { line : 17 , column : 11 } ] ,
623
+ } ,
624
+ {
625
+ message : 'Union type BadUnion can only include type TypeB once.' ,
626
+ locations : [ { line : 16 , column : 11 } , { line : 1 , column : 25 } ] ,
627
+ } ,
628
+ ] ) ;
605
629
} ) ;
606
630
607
631
it ( 'rejects a Union type with non-Object members types' , ( ) => {
608
- const schema = buildSchema ( `
632
+ let schema = buildSchema ( `
609
633
type Query {
610
634
test: BadUnion
611
635
}
@@ -623,13 +647,20 @@ describe('Type System: Union types must be valid', () => {
623
647
| String
624
648
| TypeB
625
649
` ) ;
650
+
651
+ schema = extendSchema ( schema , parse ( 'extend union BadUnion = Int' ) ) ;
652
+
626
653
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
627
654
{
628
655
message :
629
- 'Union type BadUnion can only include Object types, ' +
630
- 'it cannot include String.' ,
656
+ 'Union type BadUnion can only include Object types, it cannot include String.' ,
631
657
locations : [ { line : 16 , column : 11 } ] ,
632
658
} ,
659
+ {
660
+ message :
661
+ 'Union type BadUnion can only include Object types, it cannot include Int.' ,
662
+ locations : [ { line : 1 , column : 25 } ] ,
663
+ } ,
633
664
] ) ;
634
665
635
666
const badUnionMemberTypes = [
@@ -671,18 +702,28 @@ describe('Type System: Input Objects must have fields', () => {
671
702
} ) ;
672
703
673
704
it ( 'rejects an Input Object type with missing fields' , ( ) => {
674
- const schema = buildSchema ( `
705
+ let schema = buildSchema ( `
675
706
type Query {
676
707
field(arg: SomeInputObject): String
677
708
}
678
709
679
710
input SomeInputObject
680
711
` ) ;
712
+
713
+ schema = extendSchema (
714
+ schema ,
715
+ parse ( `
716
+ directive @test on ENUM
717
+
718
+ extend input SomeInputObject @test
719
+ ` ) ,
720
+ ) ;
721
+
681
722
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
682
723
{
683
724
message :
684
725
'Input Object type SomeInputObject must define one or more fields.' ,
685
- locations : [ { line : 6 , column : 7 } ] ,
726
+ locations : [ { line : 6 , column : 7 } , { line : 4 , column : 9 } ] ,
686
727
} ,
687
728
] ) ;
688
729
} ) ;
@@ -722,17 +763,27 @@ describe('Type System: Input Objects must have fields', () => {
722
763
723
764
describe ( 'Type System: Enum types must be well defined' , ( ) => {
724
765
it ( 'rejects an Enum type without values' , ( ) => {
725
- const schema = buildSchema ( `
766
+ let schema = buildSchema ( `
726
767
type Query {
727
768
field: SomeEnum
728
769
}
729
770
730
771
enum SomeEnum
731
772
` ) ;
773
+
774
+ schema = extendSchema (
775
+ schema ,
776
+ parse ( `
777
+ directive @test on ENUM
778
+
779
+ extend enum SomeEnum @test
780
+ ` ) ,
781
+ ) ;
782
+
732
783
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
733
784
{
734
785
message : 'Enum type SomeEnum must define one or more values.' ,
735
- locations : [ { line : 6 , column : 7 } ] ,
786
+ locations : [ { line : 6 , column : 7 } , { line : 4 , column : 9 } ] ,
736
787
} ,
737
788
] ) ;
738
789
} ) ;
@@ -1000,13 +1051,21 @@ describe('Type System: Interface extensions should be valid', () => {
1000
1051
extend interface AnotherInterface {
1001
1052
newField: String
1002
1053
}
1054
+
1055
+ extend type AnotherObject {
1056
+ differentNewField: String
1057
+ }
1003
1058
` ) ,
1004
1059
) ;
1005
1060
expect ( validateSchema ( extendedSchema ) ) . to . deep . equal ( [
1006
1061
{
1007
1062
message :
1008
1063
'Interface field AnotherInterface.newField expected but AnotherObject does not provide it.' ,
1009
- locations : [ { line : 3 , column : 11 } , { line : 10 , column : 7 } ] ,
1064
+ locations : [
1065
+ { line : 3 , column : 11 } ,
1066
+ { line : 10 , column : 7 } ,
1067
+ { line : 6 , column : 9 } ,
1068
+ ] ,
1010
1069
} ,
1011
1070
] ) ;
1012
1071
} ) ;
0 commit comments