public static class ApolloClient.Builder
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
ApolloClient.Builder |
addApplicationInterceptor(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).
|
<T> ApolloClient.Builder |
addCustomTypeAdapter(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.
|
ApolloClient |
build()
Builds the
ApolloClient instance using the configured values. |
ApolloClient.Builder |
callFactory(okhttp3.Call.Factory factory)
Set the custom call factory for creating
Call instances. |
ApolloClient.Builder |
defaultCacheHeaders(CacheHeaders cacheHeaders)
Set the default
CacheHeaders strategy that will be passed to the com.apollographql.apollo.interceptor.FetchOptions used in each new ApolloCall . |
ApolloClient.Builder |
defaultHttpCachePolicy(com.apollographql.apollo.api.cache.http.HttpCachePolicy.Policy cachePolicy)
Sets the http cache policy to be used as default for all GraphQL
Query operations. |
ApolloClient.Builder |
defaultResponseFetcher(ResponseFetcher defaultResponseFetcher)
Set the default
ResponseFetcher to be used with each new ApolloCall . |
ApolloClient.Builder |
dispatcher(java.util.concurrent.Executor dispatcher)
The #
Executor to use for dispatching the requests. |
ApolloClient.Builder |
enableAutoPersistedQueries(boolean enableAutoPersistedQueries) |
ApolloClient.Builder |
enableAutoPersistedSubscriptions(boolean enableAutoPersistedSubscriptions) |
ApolloClient.Builder |
httpCache(com.apollographql.apollo.api.cache.http.HttpCache httpCache)
Set the configuration to be used for request/response http cache.
|
ApolloClient.Builder |
logger(com.apollographql.apollo.Logger logger)
The
Logger to use for logging purposes. |
ApolloClient.Builder |
normalizedCache(NormalizedCacheFactory normalizedCacheFactory)
Set the configuration to be used for normalized cache.
|
ApolloClient.Builder |
normalizedCache(NormalizedCacheFactory normalizedCacheFactory,
CacheKeyResolver keyResolver)
Set the configuration to be used for normalized cache.
|
ApolloClient.Builder |
okHttpClient(okhttp3.OkHttpClient okHttpClient)
Set the
OkHttpClient to use for making network requests. |
ApolloClient.Builder |
serverUrl(okhttp3.HttpUrl serverUrl)
Set the API server's base url.
|
ApolloClient.Builder |
serverUrl(java.lang.String serverUrl)
Set the API server's base url.
|
ApolloClient.Builder |
subscriptionConnectionParams(SubscriptionConnectionParams connectionParams)
Sets up subscription connection parameters to be sent to the server when connection is established with subscription server
|
ApolloClient.Builder |
subscriptionConnectionParams(SubscriptionConnectionParamsProvider provider)
Sets up subscription connection parameters to be sent to the server when connection is established with subscription server
|
ApolloClient.Builder |
subscriptionHeartbeatTimeout(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Sets up subscription heartbeat message timeout.
|
ApolloClient.Builder |
subscriptionTransportFactory(SubscriptionTransport.Factory subscriptionTransportFactory)
Sets up subscription transport factory to be used for subscription server communication. See also:
WebSocketSubscriptionTransport |
ApolloClient.Builder |
useHttpGetMethodForPersistedQueries(boolean useHttpGetMethodForPersistedQueries)
Sets flag whether GraphQL Persisted queries should be sent via HTTP GET requests.
|
ApolloClient.Builder |
useHttpGetMethodForQueries(boolean useHttpGetMethodForQueries)
Sets flag whether GraphQL queries should be sent via HTTP GET requests.
|
public ApolloClient.Builder okHttpClient(@NotNull okhttp3.OkHttpClient okHttpClient)
OkHttpClient
to use for making network requests.okHttpClient
- the client to use.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder callFactory(@NotNull okhttp3.Call.Factory factory)
Call
instances. Note: Calling okHttpClient(OkHttpClient)
automatically sets this value.
public ApolloClient.Builder serverUrl(@NotNull okhttp3.HttpUrl serverUrl)
Set the API server's base url.
serverUrl
- the url to set.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder serverUrl(@NotNull java.lang.String serverUrl)
Set the API server's base url.
serverUrl
- the url to set.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder httpCache(@NotNull com.apollographql.apollo.api.cache.http.HttpCache httpCache)
httpCache
- The to use for reading and writing cached response.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder normalizedCache(@NotNull NormalizedCacheFactory normalizedCacheFactory)
normalizedCacheFactory
- the NormalizedCacheFactory
used to construct a NormalizedCache
.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder normalizedCache(@NotNull NormalizedCacheFactory normalizedCacheFactory, @NotNull CacheKeyResolver keyResolver)
normalizedCacheFactory
- the NormalizedCacheFactory
used to construct a NormalizedCache
.keyResolver
- the CacheKeyResolver
to use to normalize recordsApolloClient.Builder
object to be used for chaining method callspublic <T> ApolloClient.Builder addCustomTypeAdapter(@NotNull com.apollographql.apollo.api.ScalarType scalarType, @NotNull com.apollographql.apollo.api.CustomTypeAdapter<T> customTypeAdapter)
T
- the value typescalarType
- the scalar type to serialize/deserializecustomTypeAdapter
- the type adapter to useApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder dispatcher(@NotNull java.util.concurrent.Executor dispatcher)
Executor
to use for dispatching the requests.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder defaultHttpCachePolicy(@NotNull com.apollographql.apollo.api.cache.http.HttpCachePolicy.Policy cachePolicy)
Query
operations. Will be ignored for
any Mutation
operations. By default http cache policy is set to HttpCachePolicy.NETWORK_ONLY
.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder defaultCacheHeaders(@NotNull CacheHeaders cacheHeaders)
CacheHeaders
strategy that will be passed to the com.apollographql.apollo.interceptor.FetchOptions
used in each new ApolloCall
.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder defaultResponseFetcher(@NotNull ResponseFetcher defaultResponseFetcher)
ResponseFetcher
to be used with each new ApolloCall
.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder logger(@Nullable com.apollographql.apollo.Logger logger)
Logger
to use for logging purposes.ApolloClient.Builder
object to be used for chaining method callspublic 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.
interceptor
- Application level interceptor to addApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder enableAutoPersistedQueries(boolean enableAutoPersistedQueries)
enableAutoPersistedQueries
- True if ApolloClient should enable Automatic Persisted Queries support.
Default: false.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder subscriptionTransportFactory(@NotNull SubscriptionTransport.Factory subscriptionTransportFactory)
Sets up subscription transport factory to be used for subscription server communication.
See also:WebSocketSubscriptionTransport
subscriptionTransportFactory
- transport layer to be used for subscriptions.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder subscriptionConnectionParams(@NotNull SubscriptionConnectionParams connectionParams)
Sets up subscription connection parameters to be sent to the server when connection is established with subscription server
connectionParams
- map of connection parameters to be sentApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder subscriptionConnectionParams(@NotNull SubscriptionConnectionParamsProvider provider)
Sets up subscription connection parameters to be sent to the server when connection is established with subscription server
provider
- connection parameters providerApolloClient.Builder
object to be used for chaining method callspublic 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.timeout
- connection keep alive timeout. Min value is 10 secs.timeUnit
- time unitApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder enableAutoPersistedSubscriptions(boolean enableAutoPersistedSubscriptions)
enableAutoPersistedSubscriptions
- True if ApolloClient should enable Automatic Persisted Subscriptions support. Default: false.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder useHttpGetMethodForQueries(boolean useHttpGetMethodForQueries)
useHttpGetMethodForQueries
- true
if HTTP GET requests should be used, false
otherwise.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient.Builder useHttpGetMethodForPersistedQueries(boolean useHttpGetMethodForPersistedQueries)
useHttpGetMethodForPersistedQueries
- true
if HTTP GET requests should be used, false
otherwise.ApolloClient.Builder
object to be used for chaining method callspublic ApolloClient build()
ApolloClient
instance using the configured values.
Note that if the dispatcher
is not called, then a default Executor
is used.
ApolloClient