Registry / http-networking / apollo-client

apollo-client

JSON →
library2.1.2jsnpmunverified

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.

npm install apollo-client
INSTALL
IMPORT
SIG · APOLLO-CLIENT
A
apollo-client
http-networkingjavascriptv2.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ApolloClient
import { ApolloClient } from '@apollo/client'
import ApolloClient from 'apollo-client'
In v2, import from 'apollo-client'. In v3+ (since 2020), use '@apollo/client'. Default import in v2; named import in v3+.
gql
import { gql } from '@apollo/client'
import gql from 'graphql-tag'
gql is re-exported from @apollo/client in v3+. The graphql-tag package is still valid but the re-export is recommended for consistency.
useQuery
import { useQuery } from '@apollo/client'
import { useQuery } from 'react-apollo'
In v3+, react hooks are part of @apollo/client. In v2, use 'react-apollo' (deprecated).
InMemoryCache
import { InMemoryCache } from '@apollo/client'
import InMemoryCache from 'apollo-cache-inmemory'
In v2, separate package apollo-cache-inmemory. In v3+, integrated into @apollo/client.
HttpLink
import { HttpLink } from '@apollo/client'
import HttpLink from 'apollo-link-http'
In v2, separate package apollo-link-http. In v3+, integrated into @apollo/client.

Creates an Apollo Client instance with a GraphQL endpoint and in-memory cache, then executes a query.

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));
Debug
Known issues
breakingv3 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.
affects: >=3.0.0
breakingIn 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'`.
affects: >=3.0.0
deprecatedreact-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'`.
affects: >=3.0.0
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.
affects: >=3.0.0 <4.1.5
gotchaPersistedQueryLink 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.
affects: <4.1.4
Errors
Common errors & fixes
Error: Could not find "client" in the context or passed in as a prop.
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.
TypeError: Cannot read property 'data' of undefined
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.
Invariant Violation: You are using the simple (get) heuristic for caching.
Cache policy mismatch when using InMemoryCache with dataIdFromObject.
fix
Provide a dataIdFromObject function in the cache constructor or use typePolicies for normalization.
Could not find module 'apollo-client'
Trying to import apollo-client v2 package in a v3+ project.
fix
Install @apollo/client and update imports to `import { ApolloClient } from '@apollo/client'`.
Warning: You are using the deprecated `apollo-boost` package.
Using the deprecated preset package.
fix
Install @apollo/client instead and configure manually: `npm uninstall apollo-boost && npm install @apollo/client graphql`.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency required for GraphQL operations.
@apollo/clientrequiredThe combined package replacing apollo-client v2; install this for v3+.
graphql-tagoptionalUsed to define GraphQL queries; often installed alongside.
Agent activity
49 hits · last 30 days
node
40
Amazon
1
OpenAI (training)
1
Resources
apollo-client — npm install apollo-client · libregistry