You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide a cache.evict option to remove the related references from root queries for evicted objects
Justification
When evicting an object from cache, it is usually because it has just been deleted. At present, cache.evict will not remove the related __ref:id items from queries. This means that the developer has to write query read + update functions for every query that references this evicted object. It seems like a nice optimization to automate the removal of these orphaned references
The evict method already has all the data needed to loop the root queries and remove these references (the object cache:id).
As an aside, when evicting an item from cache, it does not seem to immediately disappear from the Apollo Dev Tools cache list, which can be confusing
The text was updated successfully, but these errors were encountered:
jamshally
changed the title
AC3 cache.evict option to clear orphaned fragment references from root queries
AC3: cache.evict option to clear orphaned fragment references from root queries
Feb 28, 2020
Exactly this! I was about to open a feature request for this, since I feel that in essence it's a tree traversal on cache.data.data. I'm thinking of writing a lib to handle this, but it would be interesting if @benjamn could let us know whether there there are problems with this approach (or even if this is planned)
Right now the options seem to be the already mentioned read + write, custom typePolicies read to filter out or a UI level filter.
All of them require maintaining a list of queries that need updating and are rather error-prone.
This seems like a common enough use case to warrant some abstractions. Potentially it could be an optional flag in gc.
There seem to be some more related discussions about this here #5
Feature Request
Provide a cache.evict option to remove the related references from root queries for evicted objects
Justification
When evicting an object from cache, it is usually because it has just been deleted. At present, cache.evict will not remove the related
__ref:id
items from queries. This means that the developer has to write query read + update functions for every query that references this evicted object. It seems like a nice optimization to automate the removal of these orphaned referencesThe evict method already has all the data needed to loop the root queries and remove these references (the object cache:id).
As an aside, when evicting an item from cache, it does not seem to immediately disappear from the Apollo Dev Tools cache list, which can be confusing
Cache Demo
See cache evict demo with notes here in a react-apollo-error-template here
The text was updated successfully, but these errors were encountered: