Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Input Objects do not contain non-nullable circu… #1352

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/validation/__tests__/InputObjectCircularReferences-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { describe, it } from 'mocha';
import { expectPassesRule, expectFailsRule } from './harness';
import {
InputObjectCircularReferences,
unbrokenCircularReferenceMessage,
} from '../rules/InputObjectCircularReferences';

function unbrokenCircularReference(defName, fieldName, line, column) {
return {
message: unbrokenCircularReferenceMessage(defName, fieldName),
locations: [{ line, column }],
};
}

describe('Validate: Executable definitions', () => {
it('Allow simple input object with nullable circular reference', () => {
expectPassesRule(
InputObjectCircularReferences,
`
input Example {
self: Example
value: String
}
`,
);
});

it('Allow input object with circular reference broken up by a list', () => {
expectPassesRule(
InputObjectCircularReferences,
`
input Example {
self: [Example!]!
value: String
}
`,
);
});

it('Reject simple input object with non-nullable circular reference', () => {
expectFailsRule(
InputObjectCircularReferences,
`
input Example {
value: String
self: Example!
}
`,
[unbrokenCircularReference('Example', 'self', 3, 8)],
);
});

it('Reject input object with non-nullable circular reference spread across multiple inputs', () => {
expectFailsRule(
InputObjectCircularReferences,
`
input First {
second: Second!
value: String
}

input Second {
first: First!
value: String
}
`,
[
unbrokenCircularReference('First', 'second', 3, 8),
unbrokenCircularReference('Second', 'first', 8, 8),
],
);
});
});