Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helper function for GQL
import com.apollographql.apollo.api.Response
internal suspend inline fun <S> runApolloRequest(block: () -> Response<S>): Result<S> = try {
val value = handleApolloRequest{(block()}
Result.success(value)
} catch (e: Exception) {
if (e is CancellationException) throw e
Timber.e("Exception from coroutine (${coroutineContext[CoroutineName]?.name}): " +
"${e.stackTraceToString()}")
Result.failure(e)
}
// call-site
val priceResult = runApolloRequest { apolloAPI.getPrice(id) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment