Creating a client


Before you can execute GraphQL operations in your app, you need to initialize an ApolloClient instance.

Basic client creation

For a basic client with a default configuration, you can initialize ApolloClient just by providing the URL to your GraphQL server.

Swift
1let client = ApolloClient(url: URL(string: "http://localhost:4000/graphql")!)

The default client configuration uses:

For more information on the in-memory normalized cache, see its documentation in Cache Setup.

To learn more about the request chain or interceptor providers, check out our Advanced networking configuration documentation.

Custom client creation

If you need to customize your networking client configuration use the designated initializer.

ApolloClient is initialized with a NetworkTransport object and an ApolloStore.

Swift
1public init(
2  networkTransport: NetworkTransport,
3  store: ApolloStore
4)

Network Transport

Apollo iOS provides the following classes that conform to the NetworkTransport protocol:

ClassDescription
RequestChainNetworkTransportPasses a request through a chain of interceptors that can interact with the request both before and after it's transmitted. Uses standard HTTP requests to communicate with the server.
WebSocketTransportTransmits all GraphQL operations via WebSocket. Requires the ApolloWebSocket library.
SplitNetworkTransportTransmits subscription operations via WebSocket and other operations via HTTP. Requires the ApolloWebSocket library.

Apollo Store

The ApolloStore is the cache used for GraphQL response data. The default cache stores response data in-memory. This data is not persisted between application runs.

To persist cache data on-disk or configure the cache further, you can provide a custom ApolloStore.

Learn more about customizing your cache with our Caching documentation.

Feedback

Edit on GitHub

Forums