Open
Description
It seems there is no validation for the argument types of custom schema directives.
Passing an argument with the wrong type to a custom schema directive doesn't throw an error during schema building, e.g. with buildASTSchema
or buildSchema
. Meanwhile, built-in schema directives like deprecated
seem to validate their argument types correctly.
This results in the arguments of a custom schema directive possibly ending up with an unexpected type and your server breaking at runtime when you figure out the bug in your schema. Notably, the type ends up being EnumValue
if it doesn't exist as this seems to be the default type.
Steps to reproduce
- Run with deno, e.g. open
deno repl
and paste in, or run from file withdeno run file.ts
import { buildSchema } from "npm:[email protected]";
const source1 = `
type Query {
# ups... forgot the quotes around the string FOOBAR
baz: Boolean @foo(bar: FOOBAR)
}
directive @foo(bar: String!) on FIELD_DEFINITION
`;
// should throw but doesn't
const schema1 = buildSchema(source1);
console.log(schema1.getQueryType()!.getFields()["baz"].astNode!.directives![0].arguments![0].value.kind);
// EnumValue
const source2 = `
type Query {
# ups... forgot the quotes around the string FOOBAR
baz: Boolean @deprecated(reason: FOOBAR)
}
`;
// correctly throws
const schema2 = buildSchema(source2);
// error: Uncaught GraphQLError: Argument "reason" has invalid value FOOBAR.
Expected result
The buildSchema(source1)
call throws like the buildSchema(source2)
does.
Actual result
The buildSchema(source1)
call doesn't throw.
Metadata
Metadata
Assignees
Labels
No labels