Class ApolloClient.Builder
- java.lang.Object
-
- com.apollographql.apollo.ApolloClient.Builder
-
- Enclosing class:
- ApolloClient
public static class ApolloClient.Builder extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ApolloClient.BuilderaddApplicationInterceptor(ApolloInterceptor interceptor)Adds an interceptor that observes the full span of each call: from before the connection is established until after the response source is selected (either the server, cache or both).ApolloClient.BuilderaddApplicationInterceptorFactory(com.apollographql.apollo.interceptor.ApolloInterceptorFactory interceptorFactory)Adds an interceptorFactory that creates interceptors that observes the full span of each call: from before the connection is established until after the response source is selected (either the server, cache or both).<T> ApolloClient.BuilderaddCustomTypeAdapter(com.apollographql.apollo.api.ScalarType scalarType, com.apollographql.apollo.api.CustomTypeAdapter<T> customTypeAdapter)Set the type adapter to use for serializing and de-serializing custom GraphQL scalar types.ApolloClientbuild()Builds theApolloClientinstance using the configured values.ApolloClient.BuildercallFactory(okhttp3.Call.Factory factory)Set the custom call factory for creatingCallinstances.ApolloClient.BuilderdefaultCacheHeaders(com.apollographql.apollo.cache.CacheHeaders cacheHeaders)Set the defaultCacheHeadersstrategy that will be passed to thecom.apollographql.apollo.interceptor.FetchOptionsused in each newApolloCall.ApolloClient.BuilderdefaultHttpCachePolicy(com.apollographql.apollo.api.cache.http.HttpCachePolicy.Policy cachePolicy)Sets the http cache policy to be used as default for all GraphQLQueryoperations.ApolloClient.BuilderdefaultResponseFetcher(ResponseFetcher defaultResponseFetcher)Set the defaultResponseFetcherto be used with each newApolloCall.ApolloClient.Builderdispatcher(java.util.concurrent.Executor dispatcher)The #Executorto use for dispatching the requests.ApolloClient.BuilderenableAutoPersistedQueries(boolean enableAutoPersistedQueries)ApolloClient.BuilderenableAutoPersistedSubscriptions(boolean enableAutoPersistedSubscriptions)ApolloClient.BuilderhttpCache(com.apollographql.apollo.api.cache.http.HttpCache httpCache)Set the configuration to be used for request/response http cache.ApolloClient.Builderlogger(com.apollographql.apollo.Logger logger)TheLoggerto use for logging purposes.ApolloClient.BuildernormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCacheFactory normalizedCacheFactory)Set the configuration to be used for normalized cache.ApolloClient.BuildernormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCacheFactory normalizedCacheFactory, com.apollographql.apollo.cache.normalized.CacheKeyResolver keyResolver)Set the configuration to be used for normalized cache.ApolloClient.BuildernormalizedCache(com.apollographql.apollo.cache.normalized.NormalizedCacheFactory normalizedCacheFactory, com.apollographql.apollo.cache.normalized.CacheKeyResolver keyResolver, boolean writeToCacheAsynchronously)Set the configuration to be used for normalized cache.ApolloClient.BuilderokHttpClient(okhttp3.OkHttpClient okHttpClient)Set theOkHttpClientto use for making network requests.ApolloClient.BuilderserverUrl(java.lang.String serverUrl)Set the API server's base url.ApolloClient.BuilderserverUrl(okhttp3.HttpUrl serverUrl)Set the API server's base url.ApolloClient.BuildersetAutoPersistedOperationsInterceptorFactory(com.apollographql.apollo.interceptor.ApolloInterceptorFactory interceptorFactory)Sets the interceptor to use for auto persisted operations.ApolloClient.BuildersubscriptionConnectionParams(SubscriptionConnectionParams connectionParams)Sets up subscription connection parameters to be sent to the server when connection is established with subscription serverApolloClient.BuildersubscriptionConnectionParams(SubscriptionConnectionParamsProvider provider)Sets up subscription connection parameters to be sent to the server when connection is established with subscription serverApolloClient.BuildersubscriptionHeartbeatTimeout(long timeout, java.util.concurrent.TimeUnit timeUnit)Sets up subscription heartbeat message timeout.ApolloClient.BuildersubscriptionTransportFactory(SubscriptionTransport.Factory subscriptionTransportFactory)Sets up subscription transport factory to be used for subscription server communication.ApolloClient.BuilderuseHttpGetMethodForPersistedQueries(boolean useHttpGetMethodForPersistedQueries)Sets flag whether GraphQL Persisted queries should be sent via HTTP GET requests.ApolloClient.BuilderuseHttpGetMethodForQueries(boolean useHttpGetMethodForQueries)Sets flag whether GraphQL queries should be sent via HTTP GET requests.
-
-
-
Method Detail
-
okHttpClient
public ApolloClient.Builder okHttpClient(@NotNull okhttp3.OkHttpClient okHttpClient)
Set theOkHttpClientto use for making network requests.- Parameters:
okHttpClient- the client to use.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
callFactory
public ApolloClient.Builder callFactory(@NotNull okhttp3.Call.Factory factory)
Set the custom call factory for creatingCallinstances.Note: Calling
okHttpClient(OkHttpClient)automatically sets this value.
-
serverUrl
public ApolloClient.Builder serverUrl(@NotNull okhttp3.HttpUrl serverUrl)
Set the API server's base url.
- Parameters:
serverUrl- the url to set.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
serverUrl
public ApolloClient.Builder serverUrl(@NotNull java.lang.String serverUrl)
Set the API server's base url.
- Parameters:
serverUrl- the url to set.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
httpCache
public ApolloClient.Builder httpCache(@NotNull com.apollographql.apollo.api.cache.http.HttpCache httpCache)
Set the configuration to be used for request/response http cache.- Parameters:
httpCache- The to use for reading and writing cached response.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
normalizedCache
public ApolloClient.Builder normalizedCache(@NotNull com.apollographql.apollo.cache.normalized.NormalizedCacheFactory normalizedCacheFactory)
Set the configuration to be used for normalized cache.- Parameters:
normalizedCacheFactory- theNormalizedCacheFactoryused to construct aNormalizedCache.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
normalizedCache
public ApolloClient.Builder normalizedCache(@NotNull com.apollographql.apollo.cache.normalized.NormalizedCacheFactory normalizedCacheFactory, @NotNull com.apollographql.apollo.cache.normalized.CacheKeyResolver keyResolver)
Set the configuration to be used for normalized cache.- Parameters:
normalizedCacheFactory- theNormalizedCacheFactoryused to construct aNormalizedCache.keyResolver- theCacheKeyResolverto use to normalize records- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
normalizedCache
public ApolloClient.Builder normalizedCache(@NotNull com.apollographql.apollo.cache.normalized.NormalizedCacheFactory normalizedCacheFactory, @NotNull com.apollographql.apollo.cache.normalized.CacheKeyResolver keyResolver, boolean writeToCacheAsynchronously)
Set the configuration to be used for normalized cache.- Parameters:
normalizedCacheFactory- theNormalizedCacheFactoryused to construct aNormalizedCache.keyResolver- theCacheKeyResolverto use to normalize recordswriteToCacheAsynchronously- If true returning response data will not wait on the normalized cache write. This can improve request performance, but means that subsequent requests are not guaranteed to hit the cache for data contained in previously received requests.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
addCustomTypeAdapter
public <T> ApolloClient.Builder addCustomTypeAdapter(@NotNull com.apollographql.apollo.api.ScalarType scalarType, @NotNull com.apollographql.apollo.api.CustomTypeAdapter<T> customTypeAdapter)
Set the type adapter to use for serializing and de-serializing custom GraphQL scalar types.- Type Parameters:
T- the value type- Parameters:
scalarType- the scalar type to serialize/deserializecustomTypeAdapter- the type adapter to use- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
dispatcher
public ApolloClient.Builder dispatcher(@NotNull java.util.concurrent.Executor dispatcher)
The #Executorto use for dispatching the requests.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
defaultHttpCachePolicy
public ApolloClient.Builder defaultHttpCachePolicy(@NotNull com.apollographql.apollo.api.cache.http.HttpCachePolicy.Policy cachePolicy)
Sets the http cache policy to be used as default for all GraphQLQueryoperations. Will be ignored for anyMutationoperations. By default http cache policy is set toHttpCachePolicy.NETWORK_ONLY.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
defaultCacheHeaders
public ApolloClient.Builder defaultCacheHeaders(@NotNull com.apollographql.apollo.cache.CacheHeaders cacheHeaders)
Set the defaultCacheHeadersstrategy that will be passed to thecom.apollographql.apollo.interceptor.FetchOptionsused in each newApolloCall.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
defaultResponseFetcher
public ApolloClient.Builder defaultResponseFetcher(@NotNull ResponseFetcher defaultResponseFetcher)
Set the defaultResponseFetcherto be used with each newApolloCall.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
logger
public ApolloClient.Builder logger(@Nullable com.apollographql.apollo.Logger logger)
TheLoggerto use for logging purposes.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
addApplicationInterceptor
public ApolloClient.Builder addApplicationInterceptor(@NotNull ApolloInterceptor interceptor)
Adds an interceptor that observes the full span of each call: from before the connection is established until after the response source is selected (either the server, cache or both). This method can be called multiple times for adding multiple application interceptors.
Note: Interceptors will be called in the order in which they are added to the list of interceptors and if any of the interceptors tries to short circuit the responses, then subsequent interceptors won't be called.
- Parameters:
interceptor- Application level interceptor to add- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
addApplicationInterceptorFactory
public ApolloClient.Builder addApplicationInterceptorFactory(@NotNull com.apollographql.apollo.interceptor.ApolloInterceptorFactory interceptorFactory)
Adds an interceptorFactory that creates interceptors that observes the full span of each call: from before the connection is established until after the response source is selected (either the server, cache or both). This method can be called multiple times for adding multiple application interceptors.
Note: Interceptors will be called in the order in which they are added to the list of interceptors and if any of the interceptors tries to short circuit the responses, then subsequent interceptors won't be called.
- Parameters:
interceptorFactory- Application level interceptor to add- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
setAutoPersistedOperationsInterceptorFactory
public ApolloClient.Builder setAutoPersistedOperationsInterceptorFactory(@Nullable com.apollographql.apollo.interceptor.ApolloInterceptorFactory interceptorFactory)
Sets the interceptor to use for auto persisted operations.
- Parameters:
interceptorFactory- interceptor to set- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
enableAutoPersistedQueries
public ApolloClient.Builder enableAutoPersistedQueries(boolean enableAutoPersistedQueries)
- Parameters:
enableAutoPersistedQueries- True if ApolloClient should enable Automatic Persisted Queries support. Default: false.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
subscriptionTransportFactory
public ApolloClient.Builder subscriptionTransportFactory(@NotNull SubscriptionTransport.Factory subscriptionTransportFactory)
Sets up subscription transport factory to be used for subscription server communication.
See also:WebSocketSubscriptionTransport- Parameters:
subscriptionTransportFactory- transport layer to be used for subscriptions.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
subscriptionConnectionParams
public ApolloClient.Builder subscriptionConnectionParams(@NotNull SubscriptionConnectionParams connectionParams)
Sets up subscription connection parameters to be sent to the server when connection is established with subscription server
- Parameters:
connectionParams- map of connection parameters to be sent- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
subscriptionConnectionParams
public ApolloClient.Builder subscriptionConnectionParams(@NotNull SubscriptionConnectionParamsProvider provider)
Sets up subscription connection parameters to be sent to the server when connection is established with subscription server
- Parameters:
provider- connection parameters provider- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
subscriptionHeartbeatTimeout
public ApolloClient.Builder subscriptionHeartbeatTimeout(long timeout, @NotNull java.util.concurrent.TimeUnit timeUnit)
Sets up subscription heartbeat message timeout. Timeout for how long subscription manager should wait for a keep-alive message from the subscription server before reconnect. NOTE: will be ignored if server doesn't send keep-alive messages.
. By default heartbeat timeout is disabled.- Parameters:
timeout- connection keep alive timeout. Min value is 10 secs.timeUnit- time unit- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
enableAutoPersistedSubscriptions
public ApolloClient.Builder enableAutoPersistedSubscriptions(boolean enableAutoPersistedSubscriptions)
- Parameters:
enableAutoPersistedSubscriptions- True if ApolloClient should enable Automatic Persisted Subscriptions support. Default: false.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
useHttpGetMethodForQueries
public ApolloClient.Builder useHttpGetMethodForQueries(boolean useHttpGetMethodForQueries)
Sets flag whether GraphQL queries should be sent via HTTP GET requests.- Parameters:
useHttpGetMethodForQueries-trueif HTTP GET requests should be used,falseotherwise.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
useHttpGetMethodForPersistedQueries
public ApolloClient.Builder useHttpGetMethodForPersistedQueries(boolean useHttpGetMethodForPersistedQueries)
Sets flag whether GraphQL Persisted queries should be sent via HTTP GET requests.- Parameters:
useHttpGetMethodForPersistedQueries-trueif HTTP GET requests should be used,falseotherwise.- Returns:
- The
ApolloClient.Builderobject to be used for chaining method calls
-
build
public ApolloClient build()
Builds theApolloClientinstance using the configured values.Note that if the
dispatcheris not called, then a defaultExecutoris used.- Returns:
- The configured
ApolloClient
-
-