Passing null variable into fields with default argument
bullno1 opened this issue · comments
Not sure if this is a bug or a feature.
Given the schema:
type Query {
articles(includeDeleted: Boolean = false): [Article]
}
And the query:
query ListArticles($includeDeleted: Boolean) {
articles(includeDeleted: $includeDeleted) { title }
}
Calling the query without providing $includeDeleted
will result in null
being passed into articles
( i.e: articles(includeDeleted: null
) while includeDeleted
was specified to default to false
. Changing the above query to:
query ListArticles($includeDeleted: Boolean = false) {
articles(includeDeleted: $includeDeleted) { title }
}
will achieve the desired result but that's a repetition of default value.
GraphQL commit: 135657f745254198f3d07e35fd3a63623144b119
This is actually an interesting case where I'd have to read the spec in order to understand exactly what is going on. I don't know the rules of how the expansion should proceed in this case. A rough guess is that if you don't provide $includeDeleted
and that parameter has no default, then the default value of the field in the schema should take precedence.
I'll have to dig a bit in the spec to figure this one out as well, and then create a test case for it.
Since Jun2018 spec, this is now a bug. The details are in #166, and we can clarify how resolution should happen. The spec now:
- accepts not providing a parameter if there is a default value for the parameter in the schema, and it doesn't matter if the argument in which the parameter is used is non-null or nullable.
So this is a bug which hinges on us becoming Jun2018 spec compliant (which we currently aren't. A couple of smaller things are missing).
Update: This is also affected by #180 which determines in detail how null
values can be passed from the client to the server.