How to make optimistic/pessimistic cache update (probably with updateQueryData
), but without knowing the arguments of previous queries?
updateQueryData(
"getItems",
HERE_ARE_THE_ARGUMENTS_I_DONT_HAVE,
(data) => {
...
}
)
For example:
getPosts
query with argssearch: number
updatePosts
mutation
Example actions:
- Go to the table, first request
getPosts
withsearch = ""
is cached. - Write in search input
abc
. - Second request
getPosts
withsearch = "abc"
is cached. - I update one element within the table with pessimistic update - successfully modifying cache of second request (previous step)
- Clear search input
- Table shows the same state from first step, even if one element should be modified
But I need universal solution. I don't know how many different cached entries will be there. And also my case is more complex, because I have other args than "search" to worry about (pagination).
Possible solutions??
- It would be perfect if there's a method to access all previous cached queries, so I could go with
updateQueryData
for each of them, but I cannot find simple way to do that. - I thought about accessing
getState()
withinonQueryStarted
and retrieving query parameters from there (in order to do above), but it's not elegant way - I thought about looking for a way to invalidate previous requests without invalidating the last request, but also cannot find it