public final class ApolloClient extends java.lang.Object implements ApolloQueryCall.Factory, ApolloMutationCall.Factory, ApolloPrefetch.Factory, ApolloSubscriptionCall.Factory
Since each ApolloClient holds its own connection pool and thread pool, it is recommended to only create a single ApolloClient and use that for execution of all the queries, as this would reduce latency and would also save memory. Conversely, creating a client for each query execution would result in resource wastage on idle pools.
See the ApolloClient.Builder class for configuring the ApolloClient.
| Modifier and Type | Class and Description |
|---|---|
static class |
ApolloClient.Builder |
| Modifier and Type | Method and Description |
|---|---|
int |
activeCallsCount()
Returns the count of
ApolloCall & ApolloPrefetch objects which are currently in progress. |
void |
addOnSubscriptionManagerStateChangeListener(OnSubscriptionManagerStateChangeListener onStateChangeListener)
Adds new listener for subscription manager state changes.
|
ApolloStore |
apolloStore()
Deprecated.
Use getApolloStore() instead.
|
static ApolloClient.Builder |
builder() |
void |
clearHttpCache()
Clear all entries from the
HttpCache, if present. |
boolean |
clearNormalizedCache()
Clear all entries from the normalized cache.
|
void |
clearNormalizedCache(ApolloStoreOperation.Callback<java.lang.Boolean> callback)
Clear all entries from the normalized cache.
|
CacheHeaders |
defaultCacheHeaders()
Deprecated.
Use getDefaultCacheHeaders() instead
|
void |
disableSubscriptions()
Call
stop on the subscriptionManager. |
void |
enableSubscriptions()
Call
start on the subscriptionManager. |
ApolloStore |
getApolloStore() |
java.util.List<ApolloInterceptor> |
getApplicationInterceptors() |
CacheHeaders |
getDefaultCacheHeaders() |
com.apollographql.apollo.api.cache.http.HttpCache |
getHttpCache() |
com.apollographql.apollo.api.ScalarTypeAdapters |
getScalarTypeAdapters() |
okhttp3.HttpUrl |
getServerUrl() |
SubscriptionManager |
getSubscriptionManager() |
SubscriptionManagerState |
getSubscriptionManagerState()
Returns the current state of subscription manager.
|
void |
idleCallback(IdleResourceCallback idleResourceCallback)
Sets the idleResourceCallback which will be called when this ApolloClient is idle.
|
<D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> |
mutate(com.apollographql.apollo.api.Mutation<D,T,V> mutation)
Creates and prepares a new
ApolloMutationCall call. |
<D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> |
mutate(com.apollographql.apollo.api.Mutation<D,T,V> mutation,
D withOptimisticUpdates)
Creates and prepares a new
ApolloMutationCall call with optimistic updates. |
ApolloClient.Builder |
newBuilder() |
<D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> |
prefetch(com.apollographql.apollo.api.Operation<D,T,V> operation)
Creates the ApolloPrefetch by wrapping the operation object inside.
|
<D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> |
query(com.apollographql.apollo.api.Query<D,T,V> query)
Creates and prepares a new
ApolloQueryCall call. |
void |
removeOnSubscriptionManagerStateChangeListener(OnSubscriptionManagerStateChangeListener onStateChangeListener)
Removes listener for subscription manager state changes.
|
<D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> |
subscribe(com.apollographql.apollo.api.Subscription<D,T,V> subscription)
Creates and prepares a new
ApolloSubscriptionCall call. |
public static ApolloClient.Builder builder()
public <D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> ApolloMutationCall<T> mutate(@NotNull com.apollographql.apollo.api.Mutation<D,T,V> mutation)
ApolloMutationCall.FactoryApolloMutationCall call.mutate in interface ApolloMutationCall.Factorymutation - the Mutation which needs to be performedApolloMutationCall call to be executed at some point in the futurepublic <D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> ApolloMutationCall<T> mutate(@NotNull com.apollographql.apollo.api.Mutation<D,T,V> mutation, @NotNull D withOptimisticUpdates)
ApolloMutationCall.FactoryCreates and prepares a new ApolloMutationCall call with optimistic updates.
ApolloStore
immediately before mutation execution. Any ApolloQueryWatcher dependent on the changed cache records will
be re-fetched.mutate in interface ApolloMutationCall.Factorymutation - the Mutation which needs to be performedwithOptimisticUpdates - optimistic updates for this mutationApolloMutationCall call to be executed at some point in the futurepublic <D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> ApolloQueryCall<T> query(@NotNull com.apollographql.apollo.api.Query<D,T,V> query)
ApolloQueryCall.FactoryApolloQueryCall call.query in interface ApolloQueryCall.Factoryquery - the operation which needs to be performedApolloQueryCall call to be executed at some point in the futurepublic <D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> ApolloPrefetch prefetch(@NotNull com.apollographql.apollo.api.Operation<D,T,V> operation)
ApolloPrefetch.Factoryprefetch in interface ApolloPrefetch.Factoryoperation - the operation which needs to be performedpublic <D extends com.apollographql.apollo.api.Operation.Data,T,V extends com.apollographql.apollo.api.Operation.Variables> ApolloSubscriptionCall<T> subscribe(@NotNull com.apollographql.apollo.api.Subscription<D,T,V> subscription)
ApolloSubscriptionCall.FactoryApolloSubscriptionCall call.subscribe in interface ApolloSubscriptionCall.Factorysubscription - to be sent to the subscription server to start listening pushed updatesApolloSubscriptionCall call to be executedpublic void addOnSubscriptionManagerStateChangeListener(@NotNull
OnSubscriptionManagerStateChangeListener onStateChangeListener)
onStateChangeListener - to be called when state changedpublic void removeOnSubscriptionManagerStateChangeListener(@NotNull
OnSubscriptionManagerStateChangeListener onStateChangeListener)
onStateChangeListener - to removepublic SubscriptionManagerState getSubscriptionManagerState()
public SubscriptionManager getSubscriptionManager()
public void enableSubscriptions()
start on the subscriptionManager.
Which will put the subscriptionManager in a connectible state if its
current state is STOPPED. This is a noop if the current state is anything
other than STOPPED.
When subscriptions are re-enabled after having been disabled, the underlying transport isn't reconnected immediately, but will be on the first new subscription created.
public void disableSubscriptions()
stop on the subscriptionManager.
Which will unsubscribe from all active subscriptions, disconnect the
underlying transport (eg websocket), and put the subscriptionManager in
the STOPPED state.
New subscriptions will fail until enableSubscriptions() is called.
@Deprecated public CacheHeaders defaultCacheHeaders()
CacheHeaders which this instance of ApolloClient was configured.public CacheHeaders getDefaultCacheHeaders()
CacheHeaders which this instance of ApolloClient was configured.public void clearHttpCache()
HttpCache, if present.public void clearNormalizedCache(@NotNull
ApolloStoreOperation.Callback<java.lang.Boolean> callback)
callback - to be notified when operation is completedpublic boolean clearNormalizedCache()
true if operation succeed, false otherwise@Deprecated public ApolloStore apolloStore()
ApolloStore managing access to the normalized cache created by ApolloClient.Builder.normalizedCache(NormalizedCacheFactory, CacheKeyResolver) }public ApolloStore getApolloStore()
ApolloStore managing access to the normalized cache created by ApolloClient.Builder.normalizedCache(NormalizedCacheFactory, CacheKeyResolver) }public okhttp3.HttpUrl getServerUrl()
HttpUrl serverUrlpublic com.apollographql.apollo.api.cache.http.HttpCache getHttpCache()
HttpCache httpCachepublic com.apollographql.apollo.api.ScalarTypeAdapters getScalarTypeAdapters()
ScalarTypeAdapters scalarTypeAdapterspublic java.util.List<ApolloInterceptor> getApplicationInterceptors()
ApolloInterceptorspublic void idleCallback(IdleResourceCallback idleResourceCallback)
public int activeCallsCount()
ApolloCall & ApolloPrefetch objects which are currently in progress.public ApolloClient.Builder newBuilder()
ApolloClient.Builder to customize an existing ApolloClient