graphql
Build and consume GraphQL APIs. Use when a user asks to create a GraphQL server, write GraphQL schemas, implement resolvers, set up subscriptions, build a GraphQL API, add authentication to GraphQL, optimize queries with DataLoader, implement pagination, handle file uploads, generate types from schema, consume a GraphQL endpoint, or migrate from REST to GraphQL. Covers Apollo Server, Apollo Client, schema design, resolvers, subscriptions, federation, and production patterns.
What this skill does
# GraphQL
## Overview
Design, build, and consume GraphQL APIs. This skill covers schema-first and code-first approaches, resolver patterns, real-time subscriptions, authentication, performance optimization with DataLoader, pagination, federation for microservices, and client-side consumption with Apollo Client.
## Instructions
### Step 1: Project Setup
**Server (Apollo Server):**
```bash
npm install @apollo/server graphql
npm install @apollo/server express cors # With Express
npm install dataloader # For N+1 prevention
```
**Client (Apollo Client):**
```bash
npm install @apollo/client graphql
```
**Type generation:**
```bash
npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-resolvers
```
### Step 2: Schema Design
```graphql
type Query {
user(id: ID!): User
users(filter: UserFilter, pagination: PaginationInput): UserConnection!
feed(cursor: String, limit: Int = 20): PostConnection!
}
type Mutation {
createUser(input: CreateUserInput!): User!
updateUser(id: ID!, input: UpdateUserInput!): User!
createPost(input: CreatePostInput!): Post!
likePost(id: ID!): Post!
}
type Subscription {
postCreated: Post!
}
type User {
id: ID!
email: String!
name: String!
posts(limit: Int = 10): [Post!]!
createdAt: DateTime!
}
type Post {
id: ID!
title: String!
content: String!
author: User!
comments: [Comment!]!
likes: Int!
createdAt: DateTime!
}
# Relay-style cursor pagination
type UserConnection {
edges: [UserEdge!]!
pageInfo: PageInfo!
totalCount: Int!
}
type UserEdge { node: User!; cursor: String! }
type PageInfo { hasNextPage: Boolean!; hasPreviousPage: Boolean!; endCursor: String }
input CreateUserInput { email: String!; name: String! }
input UpdateUserInput { name: String; avatar: String }
input CreatePostInput { title: String!; content: String!; tags: [String!] }
input PaginationInput { first: Int; after: String }
scalar DateTime
```
Schema design rules: use `!` for non-nullable fields, input types for mutations, Relay-style connections for pagination, descriptive verb names (`createUser`, not `addUser`).
### Step 3: Resolvers
```javascript
import { GraphQLError } from 'graphql';
export const resolvers = {
Query: {
user: async (_, { id }, { dataSources }) => dataSources.users.getById(id),
users: async (_, { filter, pagination }, { dataSources }) => {
const { first = 20, after } = pagination || {};
const result = await dataSources.users.getMany({ filter, first, after });
return {
edges: result.items.map(item => ({
node: item, cursor: Buffer.from(item.id).toString('base64'),
})),
pageInfo: { hasNextPage: result.hasMore, hasPreviousPage: !!after,
endCursor: result.items.at(-1) ? Buffer.from(result.items.at(-1).id).toString('base64') : null },
totalCount: result.totalCount,
};
},
},
Mutation: {
createUser: async (_, { input }, { dataSources, user }) => {
if (!user) throw new GraphQLError('Not authenticated', { extensions: { code: 'UNAUTHENTICATED' } });
return dataSources.users.create(input);
},
createPost: async (_, { input }, { dataSources, user }) => {
if (!user) throw new GraphQLError('Not authenticated', { extensions: { code: 'UNAUTHENTICATED' } });
return dataSources.posts.create({ ...input, authorId: user.id });
},
},
User: { posts: async (parent, { limit }, { dataSources }) => dataSources.posts.getByAuthor(parent.id, limit) },
Post: { author: async (parent, _, { dataSources }) => dataSources.users.getById(parent.authorId) },
};
```
### Step 4: Server Setup with Subscriptions
```javascript
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { WebSocketServer } from 'ws';
import { useServer } from 'graphql-ws/lib/use/ws';
import express from 'express';
import cors from 'cors';
const schema = makeExecutableSchema({ typeDefs, resolvers });
const app = express();
const httpServer = require('http').createServer(app);
const wsServer = new WebSocketServer({ server: httpServer, path: '/graphql' });
useServer({ schema }, wsServer);
const server = new ApolloServer({ schema });
await server.start();
app.use('/graphql', cors(), express.json(), expressMiddleware(server, {
context: async ({ req }) => ({
user: await getUserFromToken(req.headers.authorization?.replace('Bearer ', '')),
dataSources: createDataSources(),
}),
}));
httpServer.listen(4000);
```
### Step 5: DataLoader (N+1 Problem)
```javascript
import DataLoader from 'dataloader';
export function createDataSources() {
const userLoader = new DataLoader(async (ids) => {
const users = await db.users.findMany({ where: { id: { in: ids } } });
const userMap = new Map(users.map(u => [u.id, u]));
return ids.map(id => userMap.get(id) || null); // Must return in same order as input
});
return {
users: { getById: (id) => userLoader.load(id), create: (input) => db.users.create({ data: input }) },
posts: { getByAuthor: (authorId, limit) => db.posts.findMany({ where: { authorId }, take: limit }) },
};
}
```
### Step 6: Apollo Client (React)
```jsx
import { ApolloClient, InMemoryCache, gql, useQuery, useMutation } from '@apollo/client';
const client = new ApolloClient({ uri: '/graphql', cache: new InMemoryCache() });
const GET_FEED = gql`
query GetFeed($cursor: String) {
feed(cursor: $cursor, limit: 20) {
edges { node { id title author { name } likes } cursor }
pageInfo { hasNextPage endCursor }
}
}
`;
function Feed() {
const { data, loading, fetchMore } = useQuery(GET_FEED);
if (loading) return <p>Loading...</p>;
return (
<div>
{data.feed.edges.map(({ node }) => (
<article key={node.id}><h2>{node.title}</h2><p>By {node.author.name}</p></article>
))}
{data.feed.pageInfo.hasNextPage && (
<button onClick={() => fetchMore({ variables: { cursor: data.feed.pageInfo.endCursor } })}>
Load more
</button>
)}
</div>
);
}
```
### Step 7: Security
```javascript
import depthLimit from 'graphql-depth-limit';
const server = new ApolloServer({
schema,
validationRules: [depthLimit(7)], // Prevent deeply nested abuse queries
});
// Use @cacheControl directive for response caching
// type Query { user(id: ID!): User @cacheControl(maxAge: 60) }
```
## Examples
### Example 1: Build a blog API with cursor pagination
**User prompt:** "Create a GraphQL API for a blog with users, posts, and comments. Include cursor-based pagination for the post feed and authentication for mutations."
The agent will:
1. Define the schema with `User`, `Post`, `Comment` types, `PostConnection` for Relay-style pagination, and input types for mutations
2. Set up Apollo Server with Express, configure JWT-based context extraction
3. Implement resolvers with DataLoader to batch user lookups (preventing N+1 queries when loading post authors)
4. Add cursor pagination using base64-encoded IDs as cursors in the `feed` query
5. Protect mutation resolvers with authentication checks that throw `UNAUTHENTICATED` GraphQL errors
### Example 2: Add real-time post notifications to a React app
**User prompt:** "Add a real-time subscription so users see new posts appear in the feed without refreshing the page."
The agent will:
1. Add a `Subscription { postCreated: Post! }` type to the schema
2. Set up WebSocket server alongside the HTTP server using `graphql-ws`
3. Implement a `PubSub` instance and publish events in the `createPost` mutation resolver
4. On the client, use `useSubscription` from Apollo Client with a `POST_CREATED` subscription query
5. Update the Apollo Client cache when new posts arrive via the subscription callback
## Guidelines
1. **Schema-first design** — agree on the schema before coding resolvers
2. **Always use DataLoader*Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.