-
Notifications
You must be signed in to change notification settings - Fork 2k
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
arg with null should turn to defaultValue or stay null? #210
Comments
@jardakotesovec You set |
Just to make sure its clear. Here is example. Lets say I have nullable string called In graphql-js, if I send |
@jardakotesovec oh, sorry, I've got it wrong. It seems to me, that you are right and it may be considered as a bug. |
This is expected behavior for GraphQL. The library currently does not distinguish between undefined and null values for input. So both are replaced with a default value. One nice thing about this from a server development point of view is that if you provide a default value for an argument, you can be guaranteed to always get a non-null value for that argument. Is the behavior you're describing something that you have a legitimate use case for, or was this just something that caused confusion? |
I was using connection argument I guess this could be solved easily by ENUM.. (to have 3 different states, with defaultValue). And I agree with you that this behavior is less error prone as its easy to mix up undefined/null values on client and that guarantee of having Thanks for explanation! |
@leebyron The problem here is that React and GraphQL treats null differently. In React defaults only applies to null. |
I have run into this issue again with bit different use case. So reopening for further discussion. I wonder how other deal with it. Be able differentiate (as react) between undefined and null is useful anytime you consider null as actual value. Lets say I have Therefore I update only input that is not undefined (= sent as null or not sent at all). But how about if I need to remove that age. I don't want to set age to zero, I want to say that we don't know age information and set it to Its simplified example, but I think situations when make sense to set something to null (usually for objects than numbers) is not that uncommon. |
I have similar issue to @jardakotesovec. I realize GraphQL is language agnostic so how does one deal with At the moment, for |
Perhaps one can provide additional boolean arguments like |
My solution is to create 2 separate input types, 1 for creating & 1 for updating. A little more boilerplate, but super robust. If there's a cleaner way to do it, I'd love to hear it!
|
Closing this issue in favor of graphql/graphql-spec#83 which tracks a potential path forward (though there are still open questions and concerns there) |
Seems that graphql-js treats args that are undefined (not present in json) and which are null (
null
value in json) the same way. Which is generally fine.But I have situation where I have nullable field with
defaultValue
and I expected that if I explicitly sendname: null
I will getargs.name = null
and not thedefaultValue
, which is graphql-js behavior.What do you think?
The text was updated successfully, but these errors were encountered: