Creating a client
Before you can execute GraphQL operations in your app, you need to initialize an
For a basic client with a default configuration, you can initialize
ApolloClient just by providing the
URL to your GraphQL server.
let client = ApolloClient(url: URL(string: "http://localhost:4000/graphql")!)
The default client configuration uses:
InMemoryNormalizedCachefor caching response data in-memory.
RequestChainNetworkTransportconfigured to communicate with a spec-compliant GraphQL server over HTTP.
- Reading/writing response data to the normalized cache.
- Sending network requests using
- Parsing GraphQL response data in JSON format
- Automatic Persisted Queries.
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.
If you need to customize your networking client configuration use the designated initializer.
ApolloClient is initialized with a
NetworkTransport object and an
public init(networkTransport: NetworkTransport,store: ApolloStore)
Apollo iOS provides the following classes that conform to the
|Passes 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.|
|Transmits all GraphQL operations via WebSocket. Requires the |
|Transmits subscription operations via WebSocket and other operations via HTTP. Requires 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
Learn more about customizing your cache with our Caching documentation.