Frank Sullivan
08/02/2023, 6:19 PMbod
08/02/2023, 7:10 PMApolloStore.remove
but it’s not per Query but per cache key, so it requires a bit of fiddling.Frank Sullivan
08/02/2023, 7:24 PMbod
08/02/2023, 7:38 PMQUERY_ROOT
but I'm guessing "Query" is probably in the same sense as the Query
in the schema - basically all the root level fields that are available.bod
08/02/2023, 7:40 PMNormalizedCache.prettifyDump(apolloStore.dump())
- I often find that just looking at it helps understanding/remembering how it all worksFrank Sullivan
08/02/2023, 8:36 PMFrank Sullivan
08/02/2023, 8:45 PMquery MyQuery($first: Int = 2) {
allFilms(first: $first) {
films {
id
title
}
}
}
If I call this 5 times with first
equal to 1, 2, 3, 4, 5, those will all have separate allFilms
root entries in the cache for each
And then if I call a Mutation to remove one of the movies (preferably Phantom Menace), then I'll need to either invalidate all of those entries or refresh themFrank Sullivan
08/02/2023, 8:45 PMmbonnin
08/02/2023, 8:54 PMfirst
is actually the number of items in the list and that all those lists overlapFrank Sullivan
08/02/2023, 8:54 PMmbonnin
08/02/2023, 8:54 PMFrank Sullivan
08/02/2023, 8:55 PMFrank Sullivan
08/02/2023, 8:57 PMfirst
param (for example) were generated by user input (e.g. by them deciding how many films they want to fetch), it would be hard to know at the time of a subsequent Mutation which queries the user might have generated. So we'd have to probably keep a history of that so we know which ones to invalidate or fetch. I don't have an idea in mind for this, just thinking out loudmbonnin
08/02/2023, 9:03 PMI think if there was a way for us to, instead of fetching those queries again, to simply invalidate them (so that it'll generate a cache miss on the next natural fetch of the data), that would be very usefulThat should be possible. If you're removing a single movie (say
id = 42
, you can build its cache key programmatically and call ApolloStore.remove(CacheKey("Movie:42"))
)mbonnin
08/02/2023, 9:03 PM42
before will be invalidatedmbonnin
08/02/2023, 9:04 PMFrank Sullivan
08/02/2023, 9:12 PMmbonnin
08/02/2023, 9:12 PMFrank Sullivan
08/02/2023, 9:17 PMwriteFragment
so I'd probably need to make Movie a fragment then?Frank Sullivan
08/02/2023, 9:18 PMFrank Sullivan
08/02/2023, 9:18 PMmbonnin
08/02/2023, 9:19 PMmbonnin
08/02/2023, 9:20 PMCacheReference("Movie:40")
CacheReference("Movie:42")
CacheReference("Movie:50")
CacheReference("Movie:7")
mbonnin
08/02/2023, 9:21 PM"Movie:42"
then there will be a cache miss on the second itemmbonnin
08/02/2023, 9:22 PM"Movie:99"
) then the list still resolvesmbonnin
08/02/2023, 9:23 PMmbonnin
08/02/2023, 9:25 PMNormalizedCache.remove(pattern)
that you could maybe use. It's a bit hackish but it might work:
apolloClient.apolloStore.accessCache { it.remove("allFilms%") }
Frank Sullivan
08/02/2023, 9:56 PMFrank Sullivan
08/02/2023, 9:56 PMFrank Sullivan
08/02/2023, 9:56 PMFrank Sullivan
08/02/2023, 9:57 PM