From d4a3f70bb809cc5b86b36137360e1be8f7288706 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 27 May 2018 02:33:56 +0300 Subject: [PATCH] Add additional test, written by @spawnia --- src/type/__tests__/validation-test.js | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/type/__tests__/validation-test.js b/src/type/__tests__/validation-test.js index cfcd3a38f7d..5572a24303d 100644 --- a/src/type/__tests__/validation-test.js +++ b/src/type/__tests__/validation-test.js @@ -761,6 +761,46 @@ describe('Type System: Input Objects must have fields', () => { ]); }); + it('rejects Input Objects with multiple non-breakable circular reference', () => { + const schema = buildSchema(` + type Query { + field(arg: SomeInputObject): String + } + + input SomeInputObject { + startLoop: AnotherInputObject! + } + + input AnotherInputObject { + closeLoop: SomeInputObject! + startSecondLoop: YetAnotherInputObject! + } + + input YetAnotherInputObject { + closeSecondLoop: AnotherInputObject! + nonNullSelf: YetAnotherInputObject! + } + `); + + expect(validateSchema(schema)).to.deep.equal([ + { + message: + 'Cannot reference Input Object "SomeInputObject" within itself through a series of non-null fields: "startLoop.closeLoop".', + locations: [{ line: 7, column: 9 }, { line: 11, column: 9 }], + }, + { + message: + 'Cannot reference Input Object "AnotherInputObject" within itself through a series of non-null fields: "startSecondLoop.closeSecondLoop".', + locations: [{ line: 12, column: 9 }, { line: 16, column: 9 }], + }, + { + message: + 'Cannot reference Input Object "YetAnotherInputObject" within itself through a series of non-null fields: "nonNullSelf".', + locations: [{ line: 17, column: 9 }], + }, + ]); + }); + it('rejects an Input Object type with incorrectly typed fields', () => { const schema = buildSchema(` type Query {