class ApolloClient
API reference
The ApolloClient
class encapsulates Apollo's core client-side API. It backs all available view-layer integrations (React, iOS, and so on).
The ApolloClient
constructor
Takes an ApolloClientOptions
parameter that supports the fields listed below.
Returns an initialized ApolloClient
object.
Example
import { ApolloClient, InMemoryCache } from '@apollo/client';const cache = new InMemoryCache();const client = new ApolloClient({// Provide required constructor fieldscache: cache,uri: 'http://localhost:4000/',// Provide some optional constructor fieldsname: 'react-web-client',version: '1.3',queryDeduplication: false,defaultOptions: {watchQuery: {fetchPolicy: 'cache-and-network',},},});
Options
Name / Type | Description |
---|---|
| The URI of the GraphQL endpoint that Apollo Client will communicate with. One of |
| You can provide an Apollo Link instance to serve as Apollo Client's network layer. For more information, see Advanced HTTP networking. One of |
| Required. The cache that Apollo Client should use to store query results locally. The recommended cache is For more information, see Configuring the cache. |
| A custom name (e.g., |
| A custom version that identifies the current version of this particular client (e.g., This is not the version of Apollo Client that you are using, but rather any version string that helps you differentiate between versions of your client. |
| When using Apollo Client for server-side rendering, set this to The default value is |
| The time interval (in milliseconds) before Apollo Client force-fetches queries after a server-side render. The default value is |
| If The default value is |
| If The default value is |
| Provide this object to set application-wide default values for options you can provide to the See the example object below. |
| If The default value is |
Example defaultOptions
object
const defaultOptions = {watchQuery: {fetchPolicy: 'cache-and-network',errorPolicy: 'ignore',},query: {fetchPolicy: 'network-only',errorPolicy: 'all',},mutate: {errorPolicy: 'all',},};
You can override any default option you specify in this object by providing a different value for the same option in individual function calls.
Note: The useQuery
hook uses Apollo Client's watchQuery
function. To set defaultOptions
when using the useQuery
hook, make sure to set them under the defaultOptions.watchQuery
property.
Functions
Options
Name / Type | Description |
---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
Options
Name / Type | Description |
---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
Options
Name / Type | Description |
---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
Options
Name / Type | Description |
---|---|
| |
| |
| |
| |
|
Arguments
Name / Type | Description |
---|---|
|
Arguments
Name / Type | Description |
---|---|
|
Arguments
Name / Type | Description |
---|---|
|
Arguments
Name / Type | Description |
---|---|
|
Arguments
Name / Type | Description |
---|---|
|
Options
Name / Type | Description |
---|---|
| |
| |
| |
|
Arguments
Name / Type | Description |
---|---|
|