https://kotlinlang.org logo
Title
j

Jeremie

10/25/2021, 4:44 PM
hmmmm can't find how to set retries in apollo3? 🤔
m

mbonnin

10/25/2021, 4:46 PM
How would you like this to work? Apollo Android 3 uses coroutines so you can use
Flow.retry{}
with Flow or a simple while loop for suspend functions
j

Jeremie

10/25/2021, 5:20 PM
I did find various result regarding flow.retry examples... but with suspend not so much. Im also wondering if I should have used flows instead of suspends... I really mostly went with that since it was what I found in a working example I based myself off of. Like with a loop id have to manually check if the request went thru, set delays before retry, etc where as with flow id be able to set it all up using parameters, unless im mistaking? Its been a minute since I did android and I just started up again, and coroutines were not a huge thing back when
m

mbonnin

10/25/2021, 5:27 PM
It all depends your strategy too. For a simple strategy, you could do something like this:
private suspend fun <D: Query.Data> ApolloClient.executeWithRetries(
      query: Query<D>,
      maxRetries: Int,
      delayMillis: Long
  ): ApolloResponse<D> {
    var retries = 0
    while (retries < maxRetries) {
      try {
        return query(query)
      } catch (e: Exception) {
        delay(delayMillis)
        retries++
      }
    }
    throw Exception("max retries reached")
  }
j

Jeremie

10/25/2021, 5:28 PM
fair enough
m

mbonnin

10/25/2021, 5:29 PM
We could add stuff like that in Apollo but we can't really make any assumption about what retry strategy is required
u

undermark5

10/27/2021, 2:42 PM
I mean, couldn’t you add something like
abstract class RetryStrategy
providing some common implementations (linear, exponential, etc)? This would provide some common strategies, but while allowing us to define our own.
m

mbonnin

10/27/2021, 3:20 PM
What I'm wondering is how much of this is docs vs actual implementations. For the
Flow
case, I'm pretty sure there are implementations out there. For the
suspend
case, it's a bit of boilerplate but maybe there are extensions to do this somewhere.
I haven't really made any research on this but feel free to open an issue and we'll dig into this