Neal Sanche
12/15/2021, 10:01 PMNeal Sanche
12/15/2021, 10:58 PMfun watch(): Flow<List<Account>> =
apolloClient.query(GetAccountsQuery())
.fetchPolicy(FetchPolicy.NetworkFirst)
.refetchPolicy(FetchPolicy.CacheOnly)
.watch()
.map { response ->
response.data!!.accounts.map { it.account }
}
I had originally set the fetch policy to CacheOnly
. And obviously this meant that if there wasn't anything in the cache, I'd be waiting until something arrived. With this change to NetworkFirst
it goes to the network, fetches data into the cache, and my code is much happier.