Skip to content

Commit d4a3f70

Browse files
committed
Add additional test, written by @spawnia
1 parent cf0c922 commit d4a3f70

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/type/__tests__/validation-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,46 @@ describe('Type System: Input Objects must have fields', () => {
761761
]);
762762
});
763763

764+
it('rejects Input Objects with multiple non-breakable circular reference', () => {
765+
const schema = buildSchema(`
766+
type Query {
767+
field(arg: SomeInputObject): String
768+
}
769+
770+
input SomeInputObject {
771+
startLoop: AnotherInputObject!
772+
}
773+
774+
input AnotherInputObject {
775+
closeLoop: SomeInputObject!
776+
startSecondLoop: YetAnotherInputObject!
777+
}
778+
779+
input YetAnotherInputObject {
780+
closeSecondLoop: AnotherInputObject!
781+
nonNullSelf: YetAnotherInputObject!
782+
}
783+
`);
784+
785+
expect(validateSchema(schema)).to.deep.equal([
786+
{
787+
message:
788+
'Cannot reference Input Object "SomeInputObject" within itself through a series of non-null fields: "startLoop.closeLoop".',
789+
locations: [{ line: 7, column: 9 }, { line: 11, column: 9 }],
790+
},
791+
{
792+
message:
793+
'Cannot reference Input Object "AnotherInputObject" within itself through a series of non-null fields: "startSecondLoop.closeSecondLoop".',
794+
locations: [{ line: 12, column: 9 }, { line: 16, column: 9 }],
795+
},
796+
{
797+
message:
798+
'Cannot reference Input Object "YetAnotherInputObject" within itself through a series of non-null fields: "nonNullSelf".',
799+
locations: [{ line: 17, column: 9 }],
800+
},
801+
]);
802+
});
803+
764804
it('rejects an Input Object type with incorrectly typed fields', () => {
765805
const schema = buildSchema(`
766806
type Query {

0 commit comments

Comments
 (0)