Description
Any default values provided when defining an argument are currently not validated against that argument's type. So a Float
argument could be passed a string as a default value and this schema will be considered valid. Moreover, the default value will be passed as-is to the resolver instead of being coerced into an appropriate value.
As far as I can tell, the current behavior is inline with the spec. But it seems counterintuitive that doing something like this would be valid:
const assert = require('assert')
const { buildSchema, validateSchema } = require('graphql')
const schema = buildSchema(`
type Query {
foo(bar: Float = "ABC"): Float
}
`)
const errors = validateSchema(schema)
assert(errors.length > 0)
We do validate default values on variables, so I think it's reasonable to expect at least consistency with that behavior. At the very least, I think validateSchema
should be modified to validate the provided values against the argument type. I'm less certain about coercing the values, but off-hand it seems like desirable behavior as well.