Use when implementing Apollo Client patterns for queries, mutations, cache management, and local state in React applications.
View on GitHubTheBushidoCollective/han
jutsu-apollo-graphql
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-apollo-graphql/skills/apollo-client-patterns/SKILL.md -a claude-code --skill apollo-client-patternsInstallation paths:
.claude/skills/apollo-client-patterns/# Apollo Client Patterns
Master Apollo Client for building efficient GraphQL applications with proper
query management, caching strategies, and state handling.
## Overview
Apollo Client is a comprehensive state management library for JavaScript that
enables you to manage both local and remote data with GraphQL. It integrates
seamlessly with React and provides powerful caching mechanisms.
## Installation and Setup
### Installing Apollo Client
```bash
# Install Apollo Client and dependencies
npm install @apollo/client graphql
# For React applications
npm install @apollo/client graphql react
# Additional packages
npm install graphql-tag @apollo/client/link/error
```
### Basic Configuration
```javascript
// src/apollo/client.js
import {
ApolloClient,
InMemoryCache,
createHttpLink,
from
} from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
import { onError } from '@apollo/client/link/error';
const httpLink = createHttpLink({
uri: process.env.REACT_APP_GRAPHQL_URI || 'http://localhost:4000/graphql',
});
const authLink = setContext((_, { headers }) => {
const token = localStorage.getItem('authToken');
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
}
};
});
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) =>
console.error(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
}
if (networkError) {
console.error(`[Network error]: ${networkError}`);
}
});
const client = new ApolloClient({
link: from([errorLink, authLink, httpLink]),
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
posts: {
merge(existing, incoming) {
return incoming;
}
}
}
}
}
}),
defaultOptions: {
watchQuery: {
fetchPoli