Skip to content

Commit ac8f0c6

Browse files
VariablesAreInputTypesRule: add test for ignoring unknown types (#3284)
1 parent cb48918 commit ac8f0c6

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/validation/__tests__/KnownTypeNamesRule-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Validate: Known type names', () => {
5353

5454
it('unknown type names are invalid', () => {
5555
expectErrors(`
56-
query Foo($var: JumbledUpLetters) {
56+
query Foo($var: [JumbledUpLetters!]!) {
5757
user(id: 4) {
5858
name
5959
pets { ... on Badger { name }, ...PetFields }
@@ -65,7 +65,7 @@ describe('Validate: Known type names', () => {
6565
`).to.deep.equal([
6666
{
6767
message: 'Unknown type "JumbledUpLetters".',
68-
locations: [{ line: 2, column: 23 }],
68+
locations: [{ line: 2, column: 24 }],
6969
},
7070
{
7171
message: 'Unknown type "Badger".',

src/validation/__tests__/VariablesAreInputTypesRule-test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ function expectValid(queryStr: string) {
1313
}
1414

1515
describe('Validate: Variables are input types', () => {
16+
it('unknown types are ignored', () => {
17+
expectValid(`
18+
query Foo($a: Unknown, $b: [[Unknown!]]!) {
19+
field(a: $a, b: $b)
20+
}
21+
`);
22+
});
23+
1624
it('input types are valid', () => {
1725
expectValid(`
1826
query Foo($a: String, $b: [Boolean!]!, $c: ComplexInput) {

src/validation/rules/VariablesAreInputTypesRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function VariablesAreInputTypesRule(
2323
VariableDefinition(node: VariableDefinitionNode) {
2424
const type = typeFromAST(context.getSchema(), node.type);
2525

26-
if (type && !isInputType(type)) {
26+
if (type !== undefined && !isInputType(type)) {
2727
const variableName = node.variable.name.value;
2828
const typeName = print(node.type);
2929

0 commit comments

Comments
 (0)