apollo-client
Guide for building React applications with Apollo Client 4.x. Use this skill when: (1) setting up Apollo Client in a React…
Guide for writing GraphQL operations (queries, mutations, fragments) following best practices. Use this skill when: (1) writing GraphQL queries or mutations, (2) organizing operations with fragments, (3) optimizing data fetching patterns, (4) setting up type generation or
Claude Code
$ npx -y skills add apollographql/skills --skill graphql-operations --agent claude-code
Codex
$ npx skills add apollographql/skills --skill graphql-operations -a codex -y
Cursor
$ npx skills add apollographql/skills --skill graphql-operations -a cursor -y
Gemini CLI
$ npx skills add apollographql/skills --skill graphql-operations -a gemini-cli -y
GitHub Copilot
$ npx skills add apollographql/skills --skill graphql-operations -a github-copilot -y
OpenCode
$ npx skills add apollographql/skills --skill graphql-operations -a opencode -y
Windsurf
$ npx skills add apollographql/skills --skill graphql-operations -a windsurf -y
name: graphql-operations description: > Guide for writing GraphQL operations (queries, mutations, fragments) following best practices. Use this skill when: (1) writing GraphQL queries or mutations, (2) organizing operations with fragments, (3) optimizing data fetching patterns, (4) setting up type generation or linting, (5) reviewing operations for efficiency. license: MIT compatibility: Any GraphQL client (Apollo Client, urql, Relay, etc.) metadata: author: apollographql version: "1.0.1" allowed-tools: Bash(npm:*) Bash(npx:*) Read Write Edit Glob Grep
This guide covers best practices for writing GraphQL operations (queries, mutations, subscriptions) as a client developer. Well-written operations are efficient, type-safe, and maintainable.
Write every operation against the project's schema, not against the examples in this guide.
1. Find the schema before you write anything. Check the `schema` entry in `codegen.ts`, `graphql.config.*`, or `apollo.config.*`, then look for `*.graphql` SDL files. 2. Use only the fields, arguments, and enum values that the schema defines. Field names in this guide, such as `updatedAt` or `orderBy: { field: CREATED_AT, direction: DESC }`, are illustrations. 3. Save the operation as a document next to the client's existing operations. Leave the server schema unchanged unless the user asks for a schema change.
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
}
}mutation CreatePost($input: CreatePostInput!) {
createPost(input: $input) {
id
title
createdAt
}
}subscription OnMessageReceived($channelId: ID!) {
messageReceived(channelId: $channelId) {
id
content
sender {
id
name
}
}
}| Pattern | Example | | ------------ | ------------------------------------------- | | Query | `GetUser`, `ListPosts`, `SearchProducts` | | Mutation | `CreateUser`, `UpdatePost`, `DeleteComment` | | Subscription | `OnMessageReceived`, `OnUserStatusChanged` |
# Required variable
query GetUser($id: ID!) { ... }
# Optional variable with default
query ListPosts($first: Int = 20) { ... }
# Multiple variables
query SearchPosts($query: String!, $status: PostStatus, $first: Int = 10) { ... }# Define fragment
fragment UserBasicInfo on User {
id
name
avatarUrl
}
# Use fragment
query GetUser($id: ID!) {
user(id: $id) {
...UserBasicInfo
email
}
}query GetUser($id: ID!, $includeEmail: Boolean!) {
user(id: $id) {
id
name
email @include(if: $includeEmail)
}
}
query GetPosts($skipDrafts: Boolean!) {
posts {
id
title
draft @skip(if: $skipDrafts)
}
}# Good: Specific fields
query GetUserName($id: ID!) {
user(id: $id) {
id
name
}
}
# Avoid: Over-fetching
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
bio
posts {
id
title
content
comments {
id
}
}
followers {
id
name
}
# ... many unused fields
}
}# Good: Named operation
query GetUserPosts($userId: ID!) {
user(id: $userId) {
posts {
id
title
}
}
}
# Avoid: Anonymous operation
query {
user(id: "123") {
posts {
id
title
}
}
}# Good: Variables
query GetUser($id: ID!) {
user(id: $id) {
id
name
}
}
# Avoid: Hardcoded values
query {
user(id: "123") {
id
name
}
}// UserAvatar.tsx
export const USER_AVATAR_FRAGMENT = gql`
fragment UserAvatar on User {
id
name
avatarUrl
}
`;
function UserAvatar({ user }) {
return <img src={user.avatarUrl} alt={user.name} />;
}Detailed documentation for specific topics:
A collection of skills for AI coding agents working with Apollo GraphQL tools and technologies. Apollo Skills follow the Agent Skills format and are available on skills.sh.
Guide for building React applications with Apollo Client 4.x. Use this skill when: (1) setting up Apollo Client in a React…
DEPRECATED: superseded by the graphos-factory skill (npx skills add apollographql/skills@graphos-factory), which builds and…
Guide for authoring Apollo Federation subgraph schemas. Use this skill when: (1) creating new subgraph schemas for a federated…
Guide for building Apple-platform applications with Apollo iOS, the strongly-typed GraphQL client for Swift. Use this skill when:…
Guide for building applications with Apollo Kotlin, the GraphQL client library for Android and Kotlin. Use this skill when: (1)…
Guide for using Apollo MCP Server to connect AI agents with GraphQL APIs. Use this skill when: (1) setting up or configuring…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.