Apollo Client
raw JSON → 2.6.10 verified Sat Apr 25 auth: no javascript
Apollo Client is a comprehensive GraphQL client for JavaScript applications, providing caching, state management, and integrations with React, Angular, Vue, and other frameworks. The current stable version is 4.1.9 (2025-01-14), with a legacy v2.6.10 still in use. Major versions have breaking changes: v3 introduced a new package structure (@apollo/client), removed the separate apollo-boost preset, and switched to a single combined package. v4 (alpha) introduces modern method signatures. Key differentiators: normalized in-memory cache, optimistic UI, pagination helpers, and developer tools. It requires a GraphQL schema and is compatible with any GraphQL server. Release cadence is rapid with frequent patches.
Common errors
error Error: Could not find "client" in the context or passed in as a prop. ↓
cause Missing ApolloProvider wrapping the component tree or client prop not passed to useQuery.
fix
Wrap your app with <ApolloProvider client={client}> or pass client directly to useQuery.
error TypeError: Cannot read property 'data' of undefined ↓
cause Query result is undefined due to network error or missing cache.
fix
Check network connectivity, ensure the GraphQL endpoint is correct, and handle loading/error states.
error Invariant Violation: You are using the simple (get) heuristic for caching. ↓
cause Cache policy mismatch when using InMemoryCache with dataIdFromObject.
fix
Provide a dataIdFromObject function in the cache constructor or use typePolicies for normalization.
error Could not find module 'apollo-client' ↓
cause Trying to import apollo-client v2 package in a v3+ project.
fix
Install @apollo/client and update imports to
import { ApolloClient } from '@apollo/client'. error Warning: You are using the deprecated `apollo-boost` package. ↓
cause Using the deprecated preset package.
fix
Install @apollo/client instead and configure manually:
npm uninstall apollo-boost && npm install @apollo/client graphql. Warnings
breaking v3 migrates from separate packages (apollo-client, apollo-cache-inmemory, apollo-link-http) to a single @apollo/client package. ↓
fix Replace imports from 'apollo-client' etc. with '@apollo/client'. Update dependencies accordingly.
breaking In v3, ApolloClient is a named export, not default. v2 had default export. ↓
fix Change `import ApolloClient from 'apollo-client'` to `import { ApolloClient } from '@apollo/client'`.
deprecated react-apollo package is deprecated; React hooks are now part of @apollo/client. ↓
fix Use `import { useQuery } from '@apollo/client'` instead of `import { useQuery } from 'react-apollo'`.
gotcha `useQuery` will poll when `pollInterval` is set, even if `skip` is true. Fixed in v4.1.5+. ↓
fix Upgrade to @apollo/client@4.1.5 or later, or manage polling manually with skip logic.
gotcha PersistedQueryLink may overwrite http/fetchOptions context values instead of merging. Fixed in v4.1.4+. ↓
fix Upgrade to @apollo/client@4.1.4+ or implement custom merge logic.
Install
npm install apollo-client yarn add apollo-client pnpm add apollo-client Imports
- ApolloClient wrong
import ApolloClient from 'apollo-client'correctimport { ApolloClient } from '@apollo/client' - gql wrong
import gql from 'graphql-tag'correctimport { gql } from '@apollo/client' - useQuery wrong
import { useQuery } from 'react-apollo'correctimport { useQuery } from '@apollo/client' - InMemoryCache wrong
import InMemoryCache from 'apollo-cache-inmemory'correctimport { InMemoryCache } from '@apollo/client' - HttpLink wrong
import HttpLink from 'apollo-link-http'correctimport { HttpLink } from '@apollo/client'
Quickstart
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const client = new ApolloClient({
uri: process.env.GRAPHQL_ENDPOINT ?? 'https://api.example.com/graphql',
cache: new InMemoryCache()
});
client.query({
query: gql`
query GetData {
users {
id
name
}
}
`
}).then(result => console.log(result.data));