Class ApolloClient.Builder

  • Enclosing class:
    ApolloClient

    public static class ApolloClient.Builder
    extends java.lang.Object
    • Method Detail

      • okHttpClient

        public ApolloClient.Builder okHttpClient​(@NotNull
                                                 okhttp3.OkHttpClient okHttpClient)
        Set the OkHttpClient to use for making network requests.
        Parameters:
        okHttpClient - the client to use.
        Returns:
        The ApolloClient.Builder object to be used for chaining method calls
      • 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.Builder object 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.Builder object 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.Builder object 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 - the NormalizedCacheFactory used to construct a NormalizedCache.
        Returns:
        The ApolloClient.Builder object 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 - the NormalizedCacheFactory used to construct a NormalizedCache.
        keyResolver - the CacheKeyResolver to use to normalize records
        Returns:
        The ApolloClient.Builder object 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 - the NormalizedCacheFactory used to construct a NormalizedCache.
        keyResolver - the CacheKeyResolver to use to normalize records
        writeToCacheAsynchronously - 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.Builder object 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/deserialize
        customTypeAdapter - the type adapter to use
        Returns:
        The ApolloClient.Builder object to be used for chaining method calls
      • dispatcher

        public ApolloClient.Builder dispatcher​(@NotNull
                                               java.util.concurrent.Executor dispatcher)
        The #Executor to use for dispatching the requests.
        Returns:
        The ApolloClient.Builder object 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 GraphQL Query operations. Will be ignored for any Mutation operations. By default http cache policy is set to HttpCachePolicy.NETWORK_ONLY.
        Returns:
        The ApolloClient.Builder object to be used for chaining method calls
      • defaultCacheHeaders

        public ApolloClient.Builder defaultCacheHeaders​(@NotNull
                                                        com.apollographql.apollo.cache.CacheHeaders cacheHeaders)
        Set the default CacheHeaders strategy that will be passed to the com.apollographql.apollo.interceptor.FetchOptions used in each new ApolloCall.
        Returns:
        The ApolloClient.Builder object to be used for chaining method calls
      • logger

        public ApolloClient.Builder logger​(@Nullable
                                           com.apollographql.apollo.Logger logger)
        The Logger to use for logging purposes.
        Returns:
        The ApolloClient.Builder object 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.Builder object 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.Builder object 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.Builder object 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.Builder object 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.Builder object 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.Builder object 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.Builder object 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.Builder object 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.Builder object 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 - true if HTTP GET requests should be used, false otherwise.
        Returns:
        The ApolloClient.Builder object 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 - true if HTTP GET requests should be used, false otherwise.
        Returns:
        The ApolloClient.Builder object to be used for chaining method calls