Store ListQuery not updated after mutation
See original GitHub issueHi,
following situation:
- I have a Query to get a list of items
- a react component to render the list
- a mutation to add an item
- a react component to render a form and use the mutation to create a new item
- the form is rendered in a new page, the list component gets unmounted
In the mutation options i define the list in the refetchQueries
. In the network tab the refetch is executed, the new item is included in the result, in the apollo dev tools cache the new item is added. The list in the root query does not include the new item. When i get back to the page where the list is rendered the new item is missing.
Weird: if i render the form in an overlay (the list component doesn’t get unmounted) the refetchQuery
works as aspected and the new item is in the new list.
I guess i can use the update
in the mutation to add the item manually to the list, but the list is filtered and sorted and would not add this logic to the client, also it works when the list component doesn’t get unmounted. Or use the fetchPolicy: 'network-only'
but this is not long term solution.
I’ve found this similar issues: https://github.com/apollographql/apollo-client/issues/1290 but its almost one year old and no new activity.
Did anybody had the same issue and can help?
Many thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:6
Top GitHub Comments
I have a similar issue. When editing and refetching query, all changes are present. But when an item is added, despite it is returned from the server, it is not present in
data.queryName
list.fetchPolicy: 'cache-and-network',
didn’t helped.Using:
Have same issue with:
But
cache-and-network
helps. Actually I prefer behaviour withcache-and-network
but issue should be fixed anyway