Skip to content

Instantly share code, notes, and snippets.

@chenzhang2006
Last active April 1, 2022 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenzhang2006/58cf44dae447d338a0b18aa49ffd67fa to your computer and use it in GitHub Desktop.
Save chenzhang2006/58cf44dae447d338a0b18aa49ffd67fa to your computer and use it in GitHub Desktop.
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