Build React apps with Apollo Client - queries, mutations, cache, and subscriptions
View on GitHubpluginagentmarketplace/custom-plugin-graphql
developer-roadmap
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-graphql/blob/main/skills/graphql-apollo-client/SKILL.md -a claude-code --skill graphql-apollo-clientInstallation paths:
.claude/skills/graphql-apollo-client/# Apollo Client Skill
> Master GraphQL in React applications
## Overview
Learn to integrate Apollo Client with React, including hooks, cache management, optimistic updates, and real-time subscriptions.
---
## Quick Reference
| Hook | Purpose | Returns |
|------|---------|---------|
| `useQuery` | Fetch data | `{ data, loading, error, refetch }` |
| `useMutation` | Modify data | `[mutate, { data, loading, error }]` |
| `useSubscription` | Real-time | `{ data, loading, error }` |
| `useLazyQuery` | On-demand fetch | `[execute, { data, loading }]` |
---
## Core Patterns
### 1. Client Setup
```typescript
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
createHttpLink,
from
} from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
import { onError } from '@apollo/client/link/error';
// HTTP connection
const httpLink = createHttpLink({
uri: 'http://localhost:4000/graphql',
credentials: 'include',
});
// Auth header
const authLink = setContext((_, { headers }) => ({
headers: {
...headers,
authorization: localStorage.getItem('token')
? `Bearer ${localStorage.getItem('token')}`
: '',
},
}));
// Error handling
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, extensions }) => {
if (extensions?.code === 'UNAUTHENTICATED') {
window.location.href = '/login';
}
});
}
});
// Cache with type policies
const cache = new InMemoryCache({
typePolicies: {
User: { keyFields: ['id'] },
Query: {
fields: {
users: {
keyArgs: ['filter'],
merge(existing, incoming, { args }) {
if (!args?.after) return incoming;
return {
...incoming,
edges: [...(existing?.edges || []), ...incoming.edges],
};
},
},
},
},
},
});
// Client
const client = new ApolloClient({
link: from([errorLink, a