| title | class ApolloClient |
|---|---|
| description | API reference |
| order | 11 |
{/* @import {MDXProvidedComponents} from '../../../shared/MdxProvidedComponents.js' */}
The ApolloClient class encapsulates Apollo's core client-side API. It backs all available view-layer integrations (React, iOS, and so on).
<DocBlock canonicalReference={"@apollo/client!ApolloClient:constructor(1)"} />
Takes an ApolloClientOptions parameter that supports the fields listed below.
Returns an initialized ApolloClient object.
For more information on the defaultOptions object, see the Default Options section below.
<InterfaceDetails canonicalReference="@apollo/client!ApolloClient.Options:interface" headingLevel={3} displayName="ApolloClient.Options" customPropertyOrder={[ "cache", "link", "uri", "connectToDevTools", "defaultOptions", "name", "version", ]} />
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
useQueryhook uses Apollo Client'swatchQueryfunction. To setdefaultOptionswhen using theuseQueryhook, make sure to set them under thedefaultOptions.watchQueryproperty.