Closed myronmarston closed 4 weeks ago
Hey, thanks for the detailed write-up and sorry it took me a while to write back. I've worked up a fix over in #5133.
Are there any cases where I should expect operation variables and inline arguments to behave differently?
I think the short answer is no -- they're supposed to work the same!
Describe the bug
Non-nullable input field default values work correctly when using inline argument values, but appear to be ignored when using operation variables.
Versions
graphql
version:2.3.18
.rails
(or other framework): N/AGraphQL schema
GraphQL query
This query works as expected:
But if I use a variable for
operands
, it unexpectedly fails:Steps to reproduce
Put this into a script and run it:
Expected behavior
I expect output like:
Actual behavior
I instead get output like:
Additional context
The GraphQL spec covers this situation:
In this case, the field has a default value, so it should be treated as optional.
Note that if I make the
base
input field nullable, the default value is respected and the problem goes away. However, that allows a client to explicitly passbase: null
which breaks the resolver implementation (it relies onbase
always having an integer value, using the default of10
as needed). So I would like to keep the input field non-nullable.On a side note: I expect the same behavior whether field arguments are provided inline in the query or provided via operation variables, and was quite surprised to learn of the difference here. My test suite tends to just use inline arguments for simplicity, which allowed this issue to get through to production.
Are there any cases where I should expect operation variables and inline arguments to behave differently?