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