-
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
Should a variable value of undefined be converted to null? #2533
Comments
graphql-js converts these to null See graphql/graphql-js#2533
Variables not present within the variableValues object are left alone (https://github.com/graphql/graphql-js/blob/master/src/execution/values.js#L103) but variables present but undefined are later coerced to null. This may be by design? |
graphql-js converts these to null See graphql/graphql-js#2533
@yaacovCR Excellent question 👍
http://spec.graphql.org/draft/#sel-JANLLFCFFJCAACIB1nF But pragmatically in JS we can treat |
@yaacovCR Thinking more about this maybe we need to change this in the next major version. |
I'm not sure I understand the correspondence you're making between conversion of undefined to null within the return value of resolvers and the issue here... I would think passing a value of undefined in the variable values should be equivalent to not passing it at all and returning undefined in a resolver should be equivalent to not returning anything which should also be coerced to null... |
but in regards to your question, I am not personally sure, others might know better, actually forgot that option existed |
To use typescript terms, maybe, I think undefined and void should be treated the same within graphql-js... |
@yaacovCR I think you right.
Because of this line |
Lol, get some sleep, I am pretty sure as this is not caused an issue until now and there is an acceptable workaround in GraphQL tools already, that this is the least of all issues in terms of priority |
This is a breaking change and we can't migrate to the latest version of In some of our resolvers we pass the arguments/input directly to MongoDB as the filter object. At the very least, there could be a breaking change note on v5. If a configuration option can be made for this, even better. |
Should be fixed in v6 of graphql-tools, what version are you on? |
I was updating to v5 because I'm using Apollo Server and wanted to get rid of the fork. I wasn't considering v6 because it installs too many packages that we don't use so I'd probably wait for the Apollo team to decide the way forward on that. |
Actually, we could probably take the discussion offline as this is not really relevant to this issue...but in v6 you should be able to decrease bundle size over v5 by only including the packages you need, import from @graphql-tools/schema, @graphql-tools/wrap @graphql-tools/stitch for whatever functionality you need rather than from graphql-tools, although latter is supported for backwards compatibility. This is actually one of the main improvements in v6! If you are doing so already and bundle size has gone up, you should probably open an issue at https://github.com/ardatan/graphql-tools/issues, maybe more of the generic utility functions need to be moved elsewhere. |
This could be considered for v17 |
Updating code site: graphql-js/src/execution/values.ts Lines 186 to 202 in 76e47fc
@IvanGoncharov et al -- Can this be considered for v17? |
Actually, I think this case should not exist, and was due to improper use of getArgumentValues in client code within graphql-tools that has since been fixed. Perhaps the code could still be cleaned up, though. |
I am seeing this problem with v16.6.0. A scalar argument submitted on a mutation as |
See ardatan/graphql-tools#1453
The text was updated successfully, but these errors were encountered: