@@ -728,6 +728,120 @@ describe('Type System: Input Objects must have fields', () => {
728
728
] ) ;
729
729
} ) ;
730
730
731
+ it ( 'accepts an Input Object with breakable circular reference' , ( ) => {
732
+ const schema = buildSchema ( `
733
+ type Query {
734
+ field(arg: SomeInputObject): String
735
+ }
736
+
737
+ input SomeInputObject {
738
+ self: SomeInputObject
739
+ arrayOfSelf: [SomeInputObject]
740
+ nonNullArrayOfSelf: [SomeInputObject]!
741
+ nonNullArrayOfNonNullSelf: [SomeInputObject!]!
742
+ intermediateSelf: AnotherInputObject
743
+ }
744
+
745
+ input AnotherInputObject {
746
+ parent: SomeInputObject
747
+ }
748
+ ` ) ;
749
+
750
+ expect ( validateSchema ( schema ) ) . to . deep . equal ( [ ] ) ;
751
+ } ) ;
752
+
753
+ it ( 'rejects an Input Object with non-breakable circular reference' , ( ) => {
754
+ const schema = buildSchema ( `
755
+ type Query {
756
+ field(arg: SomeInputObject): String
757
+ }
758
+
759
+ input SomeInputObject {
760
+ nonNullSelf: SomeInputObject!
761
+ }
762
+ ` ) ;
763
+
764
+ expect ( validateSchema ( schema ) ) . to . deep . equal ( [
765
+ {
766
+ message :
767
+ 'Cannot reference Input Object "SomeInputObject" within itself through a series of non-null fields: "nonNullSelf".' ,
768
+ locations : [ { line : 7 , column : 9 } ] ,
769
+ } ,
770
+ ] ) ;
771
+ } ) ;
772
+
773
+ it ( 'rejects Input Objects with non-breakable circular reference spread across them' , ( ) => {
774
+ const schema = buildSchema ( `
775
+ type Query {
776
+ field(arg: SomeInputObject): String
777
+ }
778
+
779
+ input SomeInputObject {
780
+ startLoop: AnotherInputObject!
781
+ }
782
+
783
+ input AnotherInputObject {
784
+ nextInLoop: YetAnotherInputObject!
785
+ }
786
+
787
+ input YetAnotherInputObject {
788
+ closeLoop: SomeInputObject!
789
+ }
790
+ ` ) ;
791
+
792
+ expect ( validateSchema ( schema ) ) . to . deep . equal ( [
793
+ {
794
+ message :
795
+ 'Cannot reference Input Object "SomeInputObject" within itself through a series of non-null fields: "startLoop.nextInLoop.closeLoop".' ,
796
+ locations : [
797
+ { line : 7 , column : 9 } ,
798
+ { line : 11 , column : 9 } ,
799
+ { line : 15 , column : 9 } ,
800
+ ] ,
801
+ } ,
802
+ ] ) ;
803
+ } ) ;
804
+
805
+ it ( 'rejects Input Objects with multiple non-breakable circular reference' , ( ) => {
806
+ const schema = buildSchema ( `
807
+ type Query {
808
+ field(arg: SomeInputObject): String
809
+ }
810
+
811
+ input SomeInputObject {
812
+ startLoop: AnotherInputObject!
813
+ }
814
+
815
+ input AnotherInputObject {
816
+ closeLoop: SomeInputObject!
817
+ startSecondLoop: YetAnotherInputObject!
818
+ }
819
+
820
+ input YetAnotherInputObject {
821
+ closeSecondLoop: AnotherInputObject!
822
+ nonNullSelf: YetAnotherInputObject!
823
+ }
824
+ ` ) ;
825
+
826
+ expect ( validateSchema ( schema ) ) . to . deep . equal ( [
827
+ {
828
+ message :
829
+ 'Cannot reference Input Object "SomeInputObject" within itself through a series of non-null fields: "startLoop.closeLoop".' ,
830
+ locations : [ { line : 7 , column : 9 } , { line : 11 , column : 9 } ] ,
831
+ } ,
832
+ {
833
+ message :
834
+ 'Cannot reference Input Object "AnotherInputObject" within itself through a series of non-null fields: "startSecondLoop.closeSecondLoop".' ,
835
+ locations : [ { line : 12 , column : 9 } , { line : 16 , column : 9 } ] ,
836
+ } ,
837
+ {
838
+ message :
839
+ 'Cannot reference Input Object "YetAnotherInputObject" within itself through a series of non-null fields: "nonNullSelf".' ,
840
+ locations : [ { line : 17 , column : 9 } ] ,
841
+ } ,
842
+ ] ) ;
843
+ } ) ;
844
+
731
845
it ( 'rejects an Input Object type with incorrectly typed fields' , ( ) => {
732
846
const schema = buildSchema ( `
733
847
type Query {
0 commit comments