-
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
Updating cached data from multiple parameterized queries after a mutation #1694
Comments
Ran into the same need with |
I have the same issue, this is very common for paginated queries, and you want to update all of the cached data in the store, like for example remove an item. |
@timbrandin Maybe you can chip in here: apollographql/react-apollo#708 |
Take a look at this response... It's how I handled a similar situation: |
Thanks for opening the issue @c10b10. Let's keep all the discussion in one place: apollographql/react-apollo#708 |
Suppose I have a paginated infinite scroll list of
Items
. The list pulls data from a GraphQL server by using two parameterized queries:ITEMLIST_QUERY
andITEMLIST_MORE_QUERY
. Both of those queries have arguments for ordering, and filtering, and whatever else is needed for pagination. The only difference between them is that theMORE
query has an extra$skip
argument (I know I could have used a single query with a default$skip
set to0
, but that's not the point of the question).Now suppose a user loads a few pages of data, ie.
ITEMLIST_QUERY
gets called at component mount, data is loaded into the store, first 10Items
are rendered on the page.ITEMLIST_MORE_QUERY
gets called with a$skip: 10
arg, data is loaded into the store, the 10 new items are appened in the UI.ITEMLIST_MORE_QUERY
gets called again with a different$skip
, data is loaded into the store, the UI now contains 30 `Items.Now suppose the user clicks
Delete
for a certain item in the list, and theITEM_DELETE_MUTATION
mutation gets called.How does one update the data for the appropriate query in the store through the recommended
update
in ordered to update the UI to reflect the deletion?proxy.readQuery
seem not be able to help, since I can't be sure of the number of queries executed, or of which query contains the deletedItem
.Is there a way to get all data from all queries that match a certain pattern? For example:
It's pretty clear how to do this with the query reducer, but I'm wondering if there's a way of doing this by using
update
sincereducer
might be deprecated in the future.The text was updated successfully, but these errors were encountered: