-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
optional parameters in mutation #852
Comments
I will try to explain why I want to have this feature. I have "Main" component which can use mutation. This component has two routes. Each of them can update a different fields but when one of them wanted to save data it call mutation in the parent component via "onSubmit" callback. |
@seeden Thanks for reporting it. I think that counts as a bug, because we want to support the full GraphQL spec. |
@seeden Could you submit a PR with a failing test? I think it should be easy to do and would help us a lot! |
Yeah this is a bug where Apollo Client caching expects variables to exist in the variables dictionary: https://github.com/apollostack/apollo-client/blob/56c3cf9033f953bab07bd7d725497f4962120aec/src/data/storeUtils.ts#L62 Should be a one-line fix to replace those with We should factor out storeUtils and put them in |
@stubailo can you use undefined instead of null? Because null value is valid database value and I will use it on the server. When I get undefined I can skip it in my "update" query. I am using temporary fix for my mutation with undefined values. variables: {
title: undefined,
language: undefined,
...attributes,
}, |
Does GraphQL on the server treat undefined differently than null? |
Yes. When I send undefined I will get undefined and when I send null I will get null. If the variable is undefined I will ignore this variable on the server but I will use it with null value. I am not sure maybe you can ignore undefined variable on the client and graphql will be ok because I will not get any undefined variables |
Sounds good. If GraphQL servers treat |
Thanks @helfer for information. Working with null will be changed as you can see in the merged thread graphql/graphql-spec#83 |
@seeden which is why I said "currently" 😉 We'll wait until the changes are made in graphql-js, and then update Apollo Client accordingly. |
ok than we can use default "null" values as @stubailo mentioned because graphql has support for optional parameters in mutation |
null landed in |
I would like to use some parameters in mutations as optional. But I will get next error when I skip second "title" parameter: The inline argument title is expected as a variable but was not provided.
Here is the gql example
As you can see only id is required parameter. But when I will call next mutation I can see described error.
The truth is that I expected default "undefined" value for title.
The text was updated successfully, but these errors were encountered: