Skip to content

Latest commit

 

History

History
158 lines (139 loc) · 4.17 KB

File metadata and controls

158 lines (139 loc) · 4.17 KB
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).

The ApolloClient constructor

<DocBlock canonicalReference={"@apollo/client!ApolloClient:constructor(1)"} />

Takes an ApolloClientOptions parameter that supports the fields listed below.

Returns an initialized ApolloClient object.

Example

For more information on the defaultOptions object, see the Default Options section below.

Functions

Types

<InterfaceDetails canonicalReference="@apollo/client!ApolloClient.Options:interface" headingLevel={3} displayName="ApolloClient.Options" customPropertyOrder={[ "cache", "link", "uri", "connectToDevTools", "defaultOptions", "name", "version", ]} />

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.