-
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
Don't error if optional field not present #561
Comments
I don't think Apollo Client should take care of this. IMO the correct way to solve this is to pass |
Perhaps we could analyze the variables and automatically pass Although, perhaps we could use the nullability |
Yeah, the thing is the field is optional and if you don't pass it is not warn, it is an error. I can always pass the empty/null args, as I am doing now, but I wondered if wouldn't it be a feature |
My only reservation is that it's more code to maintain, so if it's not super valuable it might not be worth it. |
Heres how we approached it. Not sure this is correct but it solved that issue for us. We found that we needed to change our mutation schema on the server to use Then in your mutation schema you'd define formInput as a GraphQLInputObjectType. Finally client side your mutation would look something like this:
Hope that works. |
@webular it's a good approach, just tested and it works. But I usually prefer just use I think I can close it now @stubailo . |
OK, works for me! |
I don't want to be annoying but just saw that |
Ok in that case it might be a bug. |
Any update about this (possible) bug? |
@deoqc This is not a high priority for us at the moment, but if you submit a PR with a failing test case, it would help us fix it faster. |
Ok will look into it. Just asked 'cause it is annoying/error prone to always fill missing optional variables, and have this inconsistent behaviour between apollo and graphiql. |
I've been reading the GraphQL spec and it doesn't really seem clear about whether or not leaving off the value for a variable which is null is allowed or not. However, the NOTE in https://facebook.github.io/graphql/#sec-Null-Value does suggest that it should be allowed:
|
Although maybe this is a duplicate of #852, which refers to graphql/graphql-spec#83 which only added the concept of null-ness to GraphQL after the discussion in this issue! |
@glasser: yes, this is something that I will need to add to the 1.0 roadmap. Thanks for the reminder! |
Closing this in favor of #852 |
Sometimes I have a form with not all fields required, and it will be used as inputs to a mutation.
But I actually need to pass an empty
tags
tovariables
. If I pass onlyvariables: { name }
it will error.Should
apollo-client
take care of this?Right now I'm doing
variables: { tags: [], ...formFields }
instead ofvariables: formFields
sinceformFields
won't havetags
key if it is empty.The text was updated successfully, but these errors were encountered: