ApolloClient

class ApolloClient : ExecutionOptions, Closeable

The main entry point for the Apollo runtime. An ApolloClient is responsible for executing queries, mutations and subscriptions

Use ApolloClient.Builder to create a new ApolloClient:

val apolloClient = ApolloClient.Builder()
.serverUrl("https://example.com/graphql")
.build()

val response = apolloClient.query(MyQuery()).execute()
if (response.data != null) {
// Handle (potentially partial) data
} else {
// Something wrong happened
if (response.exception != null) {
// Handle fetch errors
} else {
// Handle GraphQL errors in response.errors
}
}

On native targets, ApolloClient.close must be called to release resources when not in use anymore.

Types

Link copied to clipboard

A Builder used to create instances of ApolloClient.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val canBeBatched: Boolean?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val httpHeaders: List<HttpHeader>?
Link copied to clipboard
open override val httpMethod: HttpMethod?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val sendApqExtensions: Boolean?
Link copied to clipboard
open override val sendDocument: Boolean?

Functions

Link copied to clipboard
open override fun close()

Disposes resources held by this ApolloClient. On JVM platforms, resources are ultimately garbage collected but calling close is necessary on other platform or to reclaim those resources earlier.

Link copied to clipboard
fun <D : Operation.Data> executeAsFlow(apolloRequest: ApolloRequest<D>): Flow<ApolloResponse<D>>

Low level API to execute the given apolloRequest and return a Flow.

Link copied to clipboard
fun <D : Mutation.Data> mutation(mutation: Mutation<D>): ApolloCall<D>

Creates a new ApolloCall for the given Mutation.

Link copied to clipboard

Creates a new Builder from this ApolloClient.

Link copied to clipboard
fun <D : Query.Data> query(query: Query<D>): ApolloCall<D>

Creates a new ApolloCall for the given Query.

Link copied to clipboard

Creates a new ApolloCall for the given Subscription.