Stylianos Gakis
12/07/2023, 4:26 PMwatch
on a query, smth like this
apolloClient.query(MyQuery)
.fetchPolicy(FetchPolicy.CacheOnly)
.watch(true, true) // also tried with `watch(true, true)` etc.
.onEach {
logcat { "watchMessages: #1" }
}
.retryWhen { cause, _ ->
cause is CacheMissException ||
(cause is ApolloCompositeException && cause.suppressedExceptions.any { it is CacheMissException })
}
...
I was testing the “I have no internet at all” scenario here and I have turned off wifi + data completely, and it seems to just never emit anything, which I am not sure I understand why. It never reaches the first onEach to log #1
In the scenario where there’s nothing in the cache, should it not at least either throw a CacheMissException
or just emit an empty list or something like that?
If there is already something in the cache, should it not just try and emit what was in the cache already?
And I made sure that there is no problem with the flow itself never turning hot by doing smth silly like
return flow {
logcat { "watchMessages: #0.5" }
emitAll(<the snippet above>)
}
and #0.5 is printed correctly, so for sure the flow starts.Stylianos Gakis
12/07/2023, 4:27 PMwatch
works here perhaps.
I am on 3.8.2
btw atmmbonnin
12/07/2023, 4:33 PMmbonnin
12/07/2023, 4:33 PMfetchThrows
param to workaround thatmbonnin
12/07/2023, 4:34 PMStylianos Gakis
12/07/2023, 4:39 PM.watch(fetchThrows = true, refetchThrows = true)
passed there I see no emissions on the logcat { "watchMessages: #1" }
, I would be able to see it if it did in fact throw there right?
And it should the fall down to my retryWhen
, if I understand flows correctly 😄Stylianos Gakis
12/07/2023, 4:47 PMinside
the retryWhen, there I can actually see that it gets emitted at least. Otherwise the first onEach just gets skipped I suppose, since there is an exception falling downwards, not a value!
So you are totally right, I get the exception when I am asking it to throw the exception (obviously 😂)Stylianos Gakis
12/07/2023, 4:47 PMStylianos Gakis
12/07/2023, 4:54 PM.retryWhen { cause, _ ->
val shouldRetry = cause is CacheMissException ||
(cause is ApolloCompositeException && cause.suppressedExceptions.any { it is CacheMissException })
I am afraid I will miss it otherwise if it’s inside a ApolloCompositeException
which I am not 100% confident that it’s impossible to get here, so I wanted to be safe rather than sorrymbonnin
12/07/2023, 11:14 PM```cause is CacheMissException ||
(cause is ApolloCompositeException && cause.suppressedExceptions.any { it is CacheMissException })```I don't think you need the
ApolloCompositeException
here since your fetch policy is CacheOnly
mbonnin
12/07/2023, 11:15 PMApolloCompositeException
is only for CacheFirst
NetworkFirst
and CacheAndNetwork
mbonnin
12/07/2023, 11:15 PMStylianos Gakis
12/07/2023, 11:36 PMmbonnin
12/07/2023, 11:42 PMApolloCompositeException
only existed as a way to surface exceptions if both fetches fail in a CacheFirst
query for an examplembonnin
12/07/2023, 11:43 PMmbonnin
12/07/2023, 11:43 PM