-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spec inconsistent when dealing with nullable variables #359
Comments
I agree, this is a very odd interaction between default values for variables, and explicit/implicit null values. An implicit null value causes the default value to be used, but an explicit null value does not. It seems to me that:
Alternatively, the explicit null could cause the application to observe the variable's default value. But this seems confusing, I would venture that most engineers expect explicit null's to override default values. But still, it seems quite odd to me that these two inputs would be treated differently by the server: { "variable": null } { } In the end, I think that GraphQL was more predictable when we did not try to accommodate the implicit/explicit distinction. These kinds of things are very transport-centric, but the spec has always purported to be transport-agnostic. If it were up to me, I think I would revert the addition of the But, short of that, it seems like we can certainly clarify the expectations here. Also, maybe the spec should use the term "undefined" instead of "implicit" null's. (For example, "If value is undefined" rather than "If value does not exist"). |
I believe this is a result of the spec conflating "required" and "non-nullable" - it is specified in https://facebook.github.io/graphql/#sec-Variable-Default-Values-Are-Correctly-Typed that "If variableType is non‐null it cannot have a default value", presumably because if it is non-null the user is required to specify a value so the default is useless. Now that we have explicit nulls this conflation no longer makes sense.
That was my expectation as well, and at least in the ruby implementation it does override the default value, resulting in a bug where the the field is resolved with a non-null variable set to null. Without having worked through all the implications fully, the solution I think makes the most sense is:
The result of this would be that my original example query would be malformed because it's trying to use |
These need to be treated differently since
I agree with you. Allowing That ship has sailed though. I attempted to resolve the confusion around these use cases in #418, even though I agree there are still corner cases where it is possible to create confusion - at least it should not result in clearly wrong outcomes like the one originally pointed out in this issue. Please open new issues if you spot anything not covered in #418 related to this! |
Consider the following trivial schema:
And the following query against this schema:
Even though
$variable
is nullable, the fact that it has a default value explicitly allows it to be used forargument
which is non-null (https://facebook.github.io/graphql/#sec-All-Variable-Usages-are-Allowed).Now consider what happens if I pass an explicit null for the value of
$variable
(e.g.{ "variable" => null" }
). This is in the spec as being semantically different from not providing the variable at all (https://facebook.github.io/graphql/#sec-Null-Value) so it would not be correct to use the default value. Variable validation is run against the actual type of the variable which is nullable, so it must pass (https://facebook.github.io/graphql/#sec-Coercing-Variable-Values). But the variable usage is also already validated, since it doesn't take into account the actual variable value when it's run.This is clearly wrong (you end up with a null value used for a non-null argument) but it is not clear to me what part of the validation process is supposed to fail here?
cc @rmosolgo
The text was updated successfully, but these errors were encountered: