apollo-client
apollo-client copied to clipboard
How can i filter an array of references after calling cache.evict?
For example i have a cache that looks like that:
Item:1: {
id: '1',
title: 'item 1',
__typename: 'Item'
},
Item:2: {
id: '2',
title: 'item 2',
__typename: 'Item'
},
User:1: {
id: '1',
items: [{ __ref: 'Item:1' }, { __ref: 'Item:2' }],
__typename: 'User'
}
After calling cache.evict({ id: 'Item:1' })
(and cache.gc()
after eviction) the Item:1
object is being evicted as expected but the array of references still includes Item:1
in the items
field inside User:1
Item:2: {
id: '2',
title: 'item 2',
__typename: 'Item'
},
User:1: {
id: '1',
items: [{ __ref: 'Item:1' }, { __ref: 'Item:2' }],
__typename: 'User'
}
how can i filter items
field of evicted references using typePolicies
?
i'm using "@apollo/client": "^3.3.21"
.
the only solution i came up with looks like this. am i doing something wrong?
cache.evict({ id: 'Item:1' });
cache.modify({
id: 'User:',
fields: {
items: (items, { canRead }) => items.filter(canRead),
}
});
cache.gc();
have the same problem
I have the same problem. However, if you optimistically mutate an item and evict the item afterwards, the query to get the list of items will not include the optimistic version of the item since the referenced object has been evicted.
I also still have the same issue hmm it would be better after evict and calling cache.gc() remove a ref even in array instead of using must calling filter ..!! version 3.3
is there any update for this?!