0Pricing
React Academy · Lesson

Setting Up Apollo Client in React

Configure ApolloProvider, create the Apollo client with cache and link chain, and connect to a GraphQL API.

Installing Apollo Client

Install @apollo/client and graphql. The graphql package is a peer dependency that Apollo Client requires for parsing query documents with the gql template tag.

For TypeScript projects, both packages ship their own type definitions, so no @types packages are needed.

Creating the ApolloClient Instance

Instantiate ApolloClient with a cache and a link. The simplest setup: new ApolloClient({ cache: new InMemoryCache(), uri: '/graphql' }). The uri shorthand creates an HttpLink internally.

For more control, build the link chain manually and pass it to the link option instead of uri.

All lessons in this course

  1. GraphQL Fundamentals for React Developers
  2. Setting Up Apollo Client in React
  3. useQuery and useMutation Hooks
  4. Apollo Cache: Normalization and Updates
← Back to React Academy