Input field default value is ignored
Running example can found here: https://github.com/tristanlins/graphql-input-default-test
I've build a query with an input parameter, that have default values. It looks like this:
type Query {
list(listing: Listing! = { size: 10 }): [String!]!
}
input Listing {
size: Int! = 10
after: String
}
Here are two things that I think are not working properly. First, I have to redefine the size in the parameter default value, even though it has a default value in the type definition.
Second, if I execute a query without overwriting listing, it works without problems. But if I just want to set the after value, I get an error that I should also define size - although actually a default value is defined.
Working query
query {
list
}
Result
{
"data": {
"list": [
"size: 10",
"after: null"
]
}
}
Failing query
query {
list(listing: { after: "test" })
}
Result
{
"errors": [
{
"message": "Validation error of type WrongType: argument 'listing' with value 'ObjectValue{objectFields=[ObjectField{name='after', value=StringValue{value='test'}}]}' is missing required fields '[size]' @ 'list'",
"locations": [
{
"line": 2,
"column": 8
}
],
"extensions": {
"classification": "ValidationError"
}
}
],
"data": null
}
Actually, my expectation would be that I do not have to specify size and always use the default value until I override size. So it is at least in the specification (or at least I understood it that way).
If no value is provided for a defined input object field and that field definition provides a default value, the default value should be used.
https://graphql.github.io/graphql-spec/June2018/#sec-Input-Objects
It seems that default values in input objects are currently not supported.