Skip to content

Commit

Permalink
VariablesAreInputTypesRule: add test for ignoring unknown types (#3284)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Oct 1, 2021
1 parent cb48918 commit ac8f0c6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/validation/__tests__/KnownTypeNamesRule-test.ts
Expand Up @@ -53,7 +53,7 @@ describe('Validate: Known type names', () => {

it('unknown type names are invalid', () => {
expectErrors(`
query Foo($var: JumbledUpLetters) {
query Foo($var: [JumbledUpLetters!]!) {
user(id: 4) {
name
pets { ... on Badger { name }, ...PetFields }
Expand All @@ -65,7 +65,7 @@ describe('Validate: Known type names', () => {
`).to.deep.equal([
{
message: 'Unknown type "JumbledUpLetters".',
locations: [{ line: 2, column: 23 }],
locations: [{ line: 2, column: 24 }],
},
{
message: 'Unknown type "Badger".',
Expand Down
8 changes: 8 additions & 0 deletions src/validation/__tests__/VariablesAreInputTypesRule-test.ts
Expand Up @@ -13,6 +13,14 @@ function expectValid(queryStr: string) {
}

describe('Validate: Variables are input types', () => {
it('unknown types are ignored', () => {
expectValid(`
query Foo($a: Unknown, $b: [[Unknown!]]!) {
field(a: $a, b: $b)
}
`);
});

it('input types are valid', () => {
expectValid(`
query Foo($a: String, $b: [Boolean!]!, $c: ComplexInput) {
Expand Down
2 changes: 1 addition & 1 deletion src/validation/rules/VariablesAreInputTypesRule.ts
Expand Up @@ -23,7 +23,7 @@ export function VariablesAreInputTypesRule(
VariableDefinition(node: VariableDefinitionNode) {
const type = typeFromAST(context.getSchema(), node.type);

if (type && !isInputType(type)) {
if (type !== undefined && !isInputType(type)) {
const variableName = node.variable.name.value;
const typeName = print(node.type);

Expand Down

0 comments on commit ac8f0c6

Please sign in to comment.