commonMain.com.apollographql.apollo.api.FieldResult.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-api-jvm Show documentation
Show all versions of apollo-api-jvm Show documentation
Apollo GraphQL API classes
The newest version!
package com.apollographql.apollo.api
import com.apollographql.apollo.exception.ApolloException
import com.apollographql.apollo.exception.ApolloGraphQLException
import com.apollographql.apollo.exception.DefaultApolloException
sealed interface FieldResult {
class Success(val value: V) : FieldResult
class Failure(val exception: ApolloException) : FieldResult
}
val FieldResult.isSuccess: Boolean get() = this is FieldResult.Success
fun FieldResult.getOrElse(fallback: V): V = if (this is FieldResult.Success) value else fallback
fun FieldResult.getOrNull(): V? = if (this is FieldResult.Success) value else null
fun FieldResult.exceptionOrNull(): Exception? = if (this is FieldResult.Failure) exception else null
fun FieldResult.graphQLErrorOrNull(): Error? = (exceptionOrNull() as? ApolloGraphQLException)?.error
fun FieldResult.getOrThrow(): V {
return when (this) {
is FieldResult.Success -> value
is FieldResult.Failure -> throw DefaultApolloException("Field error", exception)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy