wasyl
06/08/2021, 4:57 PMprefetch
if we’re already observing the query we want to prefetch? Will we avoid some parsing, for example?
Context: we’re trying to have a separation between observing data from cache and refreshing it. Observers will do:
val observer = apolloClient.query(operation).toBuilder()
.responseFetcher(ApolloResponseFetchers.CACHE_ONLY)
.build()
.toFlow()
and I wonder if there’s preferred refreshing method. One is prefetch:
fun refresh() = apolloClient.prefetch(operation).await()
another is a NETWORK_ONLY
request and awaiting first response:
fun refresh() = apolloClient.query(operation).toBuilder()
.responseFetcher(ApolloResponseFetchers.NETWORK_ONLY)
.build()
.toFlow()
.first()
I also see ApolloQueryWatcher#refetch
, but I don’t think it’ll work for us because it doesn’t propagate errors.
Prefetch
has some optimisations mentioned in the docs, are they relevant if we have another query observing the cache?mbonnin
06/08/2021, 5:02 PMprefetch
but I think it will save one model parsing.mbonnin
06/08/2021, 5:03 PMwasyl
06/08/2021, 5:08 PMmbonnin
06/08/2021, 5:08 PMmbonnin
06/08/2021, 5:12 PMwasyl
06/08/2021, 5:18 PMrefresh()
wouldn’t fail but observer
would. I’m afraid it’d lead to some inconsistencies, and seems like prefetch is more appropriate for fire-and-forget kind of things