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

VariablesAreInputTypesRule: add test for ignoring unknown types #3284

Merged
merged 1 commit into from Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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