Docs
Launch GraphOS Studio

Creating a client


Before you can execute 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 .

let 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.

public init(
networkTransport: NetworkTransport,
store: ApolloStore
)

Network Transport

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.

Previous
Custom Cache Keys
Next
Introduction
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company