-
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
[2.0.2] apollo-client returns empty data during mutation | bug #2496
Comments
@seeden I'll try to make a reproduction and figure this out! |
@jbaxleyiii I have the same issue, after mutation the data is empty |
For me it happens when the component with the query is unmounted and then mounted again and after that I run the mutation |
This should be fixed on master! |
Is this published? Because I am getting a similar error, below is before and after a mutation that happens in a deeply nested child component from the query component. Loading is false and no error on data. First is check if object is null (node)
Mutation happened
|
I got the same issue and struggled a lot to find the source of it. I traced it back to this part of the code which swallowed an error: try {
var data = this.dataStore.getCache().read({
query: query,
variables: variables,
previousResult: lastResult ? lastResult.data : undefined,
optimistic: true
})
return maybeDeepFreeze({ data: data, partial: false })
} catch (e) {
return maybeDeepFreeze({ data: {}, partial: true })
} The result of my mutation was missing a field that was present in the original request. query test {
house {
id
length
width
}
} mutation test {
updateHouse(id: 1) {
id
length
}
}
I'm not sure of what I have done wrong. I'm using the 2.1.0, so the code related to this PR is at least not covering all the cases. @jbaxleyiii Can you reopen this issue? |
@vincentdesmares Same happens for me. I was missing a field in my mutation that was declared in the original query and this was causing that when the mutation completed successfully and the query gets called(the second time), the data that comes in the query was an empty object. So the solution was put both the mutation and the query with the same fields. Can you please take a look at this @jbaxleyiii ? |
I've spent the last four hours trying to resolve a bug caused by the issue discussed in the last few comments here: a mutation returns a subset of the fields previously queried and cached on an object. Seems that this should be perfectly acceptable, especially if I know that my mutation isn't going to change the omitted fields. Commenting here for visibility, but I've opened a separate issue (this really is different from the original issue in this ticket): #3468. |
I have spent multiple hours on this as well. It was fixed by using a shared fragment. I had forgotten to add a field to my mutation that was on my query. |
Me too getting the same issue , i am saving the data and returning the id to use as a foreign key to the another table . But i am not getting any response , the data is coming undefined . I am not sure is this issue or i did some mistake (I am using hasura.io for graphql server). Even i checked the network tab, the response is coming fine.Any suggestions will be appreciated. |
I am not sure if it is related to apollo-client or react-apollo but I have this issue. During mutation I will get data without cached fields.
Here is steps how to reproduce it
My question is why I receive empty data.user ? Apollo client already have this data and I do not any clean cache.
My current deps:
The text was updated successfully, but these errors were encountered: