-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add functionality to remove entries from cache in ApolloStore by Operation/Fragment #77
Comments
Makes sense. I can think of 2 possible ways to do that:
The first one is easier as it doesn't require having the data but it might over-delete. For an exemple: query GetBook {
catalog {
book(id: "1") {
title
}
}
}
store.remove(GetBookQuery())
store.remove(GetBookQuery(), GetBookQuery.Data(catalog = GetBookQuery.Catalog(book = GetBookQuery.Book(title = "")) |
@martinbonnin Sorry, responding a bit late. Been looking at iOS Apollo client caching too.
So remove the root key and, if Another useful function could be to get the CacheKey from an
|
Hi 👋 sorry for the delay!
That's the thing. i.e.: # The following query will always have "catalog" as root key
query GetCatalog {
catalog {
book(id: "1") {
title
}
}
} # The root key depend on a variable here (`book($id)`)
query GetBook($id: String!) {
book(id: $id) {
title
}
} The root key can even be completely unknown at the time we send the query: # The id of the featured book is returned by the backend and might change at anytime
query GetFeaturedBook{
featuredBook {
id
title
}
}
Do you mind sharing your |
@Leevida we could add something like this: // Note how data is required in the general case
fun <D : Operation.Data> getCacheKey(operation: Operation<D>, data: D): CacheKey
fun <D : Fragment.Data> getCacheKey(fragment: Fragment<D>, data: D): CacheKey Would that help? The Something else we could do is fun <D : Operation.Data> ApolloResponse<D>.keys(): Set<CacheKey> This way you could "remember" a response and delete it when needed. Any thoughts? |
@Leevida any news? |
Here's the cache key resolver. It's just that we had some logic to switch between using
I thought apollo stores the query inside the cache and uses the query along with its parameters as the cache key (https://www.apollographql.com/blog/apollo-client/caching/demystifying-cache-normalization/#storing-the-objects-in-a-flattened-data-structure). And, if I'm not wrong, the |
Thanks for sending this!
Not really. The normalized cache stores "Records", which are flattened objects identified by a "CacheKey". For an example, assuming you have a query like this (most likely not the exact same query that you have but it should be enough as an example): query GetContentContainer {
contentContainer {
contentUrn
title
lastModified
}
} That returns the following json: "data": {
"contentContainer': {
"contentUrn": "https://example.com/content001",
"title": "Demo Content",
"last modified": "July, 29th 2021"
}
) If we need to remove this query from the cache, we need to delete the object with
Fair point. We can get the data from |
Is your feature request related to a problem? Please describe.
I think it's pretty common to want to invalidate some parts of the cache by removing entries.
ApolloStore
has some functionally to remove entries in the cache byCacheKey
, but it's hard to remove from the cache by other means, mainly by anOperation
orFragment
.Describe the solution you'd like
It would be nice to have some functions in
ApolloStore
to remove entries in the cache by theOperation
orFragment
similar to how theread()
andwrite()
methods can be called with an Operation/Fragment.Maybe something like:
The text was updated successfully, but these errors were encountered: