-
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
[3.0 Beta 41] Evict API does not support eviction based on arguments #6098
Comments
Are you comfortable with having to pass exactly the same arguments that were originally used to store the field in the cache? The only reason I ask: I don't think we can reasonably match subsets of fields if you pass some but not all of the original arguments. Of course, passing only an ID and a field name will continue to evict all variations of the field, regardless of arguments. If that feels right, then I think we could extend the API with another argument: cache.evict("ROOT_QUERY", "totalBalance", { currency: "USD" }) If I recall correctly, the reason I didn't add arguments to the |
Got it yep that sounds good to me, thanks for looking into this. I can make that change and throw up a PR. |
Hey guys! Would it be possible to have some kind of better control on the cache eviction ? So, if I understand your PR correctly, it would allow to clear the cache based on a Query name + specific variables, but the variables should be an exact match, right ? What if we wanted to have more control ? Let's say if I wanted to remove all queries We could also use a callback, to check if a query should be clear or not :
So, it would remove the cache where the currency is |
Yea so they're stored by stringified variables in the cache like this:
and you may have a number of such cached queries. The variables aren't currently stored separately so you'd have to be parsing them for each cached |
Wouldn't it be better than a useless refetch anyway ? It's one of the mail goal of GraphQL. Fetch and refetch only what you need. |
Hey @benjamn & @danReynolds ! |
Hello! I am playing around with the 3.0 eviction API. I see that we can evict by
dataId
andfieldName
. If I make two queries for a user's total balance for their currencies, they get stored in the cache under the ROOT_QUERY like this:totalBalance({ currency: 'USD' })
totalBalance({ currency: 'CAD' })
If they they added a new USD account, I want to invalidate their USD total balance by doing:
cache.evict('ROOT_QUERY', 'totalBalance({ currency: "USD" })')
But that isn't a valid field name, instead I need to do:
cache.evict('ROOT_QUERY', 'totalBalance')
But that invalidates both my cached queries. I would think that there should be a way to invalidate queries based on their arguments, since in some applications there may be many of the same query type made with different filters etc and that users can perform actions to invalidate subsets of these.
The issue is here: https://github.com/apollographql/apollo-client/blob/master/src/cache/inmemory/entityStore.ts#L130
it checks for modifiers based on the
fieldName
not thestoreFieldName
. It would be great if it could first check modifiers for the storeFieldName too, and have that modifier take precedence over the fieldName modifier. Thoughts?The text was updated successfully, but these errors were encountered: