Apollo-android: Retrying failed requests with Flow.retry

Created on 11 Feb 2020  路  2Comments  路  Source: apollographql/apollo-android

Hello 馃憢 .

I have a request that needs to be retried when there's a failure:

apolloClient
    .query(MyAwesomeQuery())
    .toFlow()
    .retry(retries = MAX_RETRY_COUNT)
    .flowOn(dispatcher)

However, retrying the request results in an IllegalStateException "Already Executed" error from Retrofit which is expected since a Retrofit call can only be executed once. When I add clone() to the request, I still get the same error.

apolloClient
    .query(MyAwesomeQuery())
    .clone()
    .toFlow()
    .retry(retries = MAX_RETRY_COUNT)
    .flowOn(dispatcher)

What is the expected behavior for ApolloQueryCall.clone()?

I'm not able to add a label, but this is a question.

coroutines-support Enhancement

Most helpful comment

I will take this issue.

All 2 comments

Looks like we need to do ApolloCall.clone inside the flow creation:

fun <T> ApolloCall<T>.toFlow(capacity: Int = Channel.UNLIMITED) = flow {
...
clone().enqueue(ChannelCallback(channel = channel))

I will take this issue.

Was this page helpful?
0 / 5 - 0 ratings