https://kotlinlang.org logo
Title
w

wasyl

05/22/2023, 11:20 AM
Quick lazy-Google question: let's say
FooQuery
fetches list of items
[a, b, c]
(with `ID`s normalized, so the items have their own entries in the cache). If I manually remove an item from the cache (using
apolloClient.apolloStore.remove(CacheKey(itemId), cascade = false)
), should I expect
FooQuery
to a) trigger refetcher b) emit
null
while
b
is missing in the cache and re-emit non-null value only when
b
is fetched, either by refetcher or some other query ?
m

mbonnin

05/22/2023, 11:22 AM
remove()
doesn't publish by default so you'd at least have to call
publish(setOf(a, b, c))
If you call
publish()
, the refetcher will be called and try to fetch according to refetchPolicy
Whether it emits
null
or
throws
depends a bunch of factors like the
refetchThrows
parameter you've passed and/or whether you're on 3.x or 4.x
w

wasyl

05/22/2023, 11:29 AM
ah perfect, yeah the emission is less of an issue, I was surprised about the publishing
Though I'm not sure how I can publish what I want 🤔 In the method to remove an item I don't know which queries depend on that item. Does
apolloClient.apolloStore.remove(CacheKey(contentId), cascade = false)
apolloClient.apolloStore.publish(setOf(contentId))
make sense or the
publish
wouldn't do anything in such case?
m

mbonnin

05/22/2023, 11:32 AM
As long as
cascade
is
false
that should be alright. But there's definitely a blind spot if
cascade
is
true
w

wasyl

05/22/2023, 11:32 AM
Right, because we'd need to publish all cascaded deletions too 🧠 Perfect, that clears things up, thank you 🙂
m

mbonnin

05/22/2023, 11:33 AM
Thanks for raising this.
w

wasyl

05/22/2023, 11:37 AM
🙇 thanks, just for clarity this is not an issue for us (we use
cascade=false
), and frankly I'd love to get rid of manipulating cache manually in the first place, only for reasons we can't do that. But the issue looks valid anyway, as the current behavior is just surprising because observing cache for the same query twice can yield different results (if you do observe — delete item — observe)