I have a problem with retryWhen operator with RxApollo. I want to call query and repeat it again. I called retryWhen operator in my Rx sequence and I got an error "Call is cancelled".
Sample of code (Kotlin):
rxApolloCall()
.flatMap { apolloCall ->
if (apolloCall.hasErrors()) {
Flowable.error<Exception>(Exception())
} else {
Flowable.just(apolloCall)
}
}
.retryWhen { sequence ->
sequence
.flatMap { exception ->
if (exception is Exception) {
Flowable.timer(1, TimeUnit.SECONDS)
} else {
Flowable.error(exception)
}
}
}
}
.subscribe(
{ result -> Log,e(result) },
{ error -> Log.e("TAG", "{$error.message}")},
{ Log.d("TAG", "completed") }
)
I'm using 0.5.0 version of apollo android support, apollo runtime and apollo rx 2.
You need to clone the call everytime, the ApolloCall is one shot deal, you can't execute it more then once, clone must be called.
I solved my problem with other GraphQL library. Thanks.
Sorry to resurrect this question, but how exactly do you achieve this then? The following simplified example is falling into the AlreadyExecuted IllegalStateException:
return Rx2Apollo.from(apolloClient.query(query).clone()).retry(2)
*Assuming, of course that something from the query causes the stream to go into error. As I said it has been simplified.
Where are we actually supposed to clone the call if Rx2Apollo is enqueuing for us and Rx's retry operator just resubscribes to the stream based on a call which has fallen into an active state.
I have used the solution of cloning the call using Rx3Aollo but same error occurred Already executed
Indeed the cloning would certainly have to happen inside the subscribe() like we did for coroutines.
Here is how I clone
apolloClient.mutate(CreatEmptyCartMutation()).clone().let {
Single.fromObservable(Rx3Apollo.from(it)).addHandlingTooManyRequests().map { it.data?.createEmptyCart }
}
then I subscribed what should I do to overcome the Already executed
Yup, your code looks good. I meant the clone should happen in the Apollo code (most likely here). I'll make a fix.
@sh3lan93 The fix is in the 2.4.1-SNAPSHOT (See https://github.com/apollographql/apollo-android#snapshots for how to include snapshots repositories). Any chance you can try it and confirm if it works?
@martinbonnin yes it working fine now 馃憦
Most helpful comment
@sh3lan93 The fix is in the 2.4.1-SNAPSHOT (See https://github.com/apollographql/apollo-android#snapshots for how to include snapshots repositories). Any chance you can try it and confirm if it works?