graphql-implementation — Claude Code skill: build GraphQL APIs
A skill for building GraphQL APIs: schema, resolvers, error codes and N+1 protection. Useful when moving off REST or adding real-time subscriptions.
npx skills add secondsky/claude-skills --skill graphql-implementation -a claude-codeWhat graphql-implementation does
The skill lays out how to work through a GraphQL API. It ships schema examples in GraphQL SDL: User and Post types, queries with limit and offset, mutations with input types such as CreateUserInput. Resolvers are shown for Apollo Server, split across Query, User and Mutation, with data pulled from dataSources.
A separate section covers DataLoader. It batches lookups by id list and kills the N+1 problem that shows up when every post fetches its author in its own query. Errors go through GraphQLError with a code in extensions, like NOT_FOUND. Python users get a Graphene reference with Flask integration: ObjectType definitions, Query and Mutation classes, input types.
The rules spell out what to avoid: deeply nested queries with no limits, leaking database internals, ignoring N+1, returning data the caller should not see. If you already run a public GraphQL endpoint without query complexity limits, that is worth a look before the next release.
What it helps with
- design a GraphQL schema around client needs
- write resolvers for queries and mutations
- batch lookups with DataLoader to avoid N+1
- return errors with codes in extensions
- add subscriptions for real-time data
Example prompts for the agent
- Design a GraphQL schema for a blog with users and posts
- Add DataLoader so the posts resolver stops querying each author separately
- Convert this REST endpoint into GraphQL mutations with input types
How to install graphql-implementation
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill graphql-implementation -a claude-code2Manually: put the files in place
~/.claude/skills/graphql-implementation/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/graphql-implementation/
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill graphql-implementation -a codex2Manually: put the files in place
.agents/skills/graphql-implementation/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill graphql-implementation -a cursor2Manually: put the files in place
.cursor/skills/graphql-implementation/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install secondsky/claude-skills graphql-implementation2Manually: put the files in place
.github/skills/graphql-implementation/SKILL.md1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill graphql-implementation -a gemini-cli2Platform CLI
gemini skills install https://github.com/secondsky/claude-skills --path plugins/graphql-implementation/skills/graphql-implementationManually: put the files in place
.devin/skills/graphql-implementation/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill graphql-implementation -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about graphql-implementation
How do I install graphql-implementation in Claude?
Run npx skills add secondsky/claude-skills --skill graphql-implementation -a claude-code. The skill lands at ~/.claude/skills/graphql-implementation/SKILL.md.
What does graphql-implementation do?
It guides GraphQL API work: schema design, resolvers, error handling and query performance. Examples cover Apollo Server, plus a Python Graphene reference with Flask.
How does the skill handle the N+1 problem?
With DataLoader, which collects ids from resolvers and issues one batched query instead of one per record. The skill's rules explicitly forbid ignoring N+1.
Source text
SKILL.md · MIT
---
name: graphql-implementation
description: Builds GraphQL APIs with schema design, resolvers, error handling, and performance optimization using Apollo or Graphene. Use when creating flexible query APIs, migrating from REST, or implementing real-time subscriptions.
license: MIT
---
# GraphQL Implementation
Build GraphQL APIs with proper schema design, resolvers, and performance optimization.
## Schema Definition
```graphql
type User {
id: ID!
name: String!
email: String!
posts(limit: Int = 10): [Post!]!
}
type Post {
id: ID!
title: String!
content: String!
author: User!
createdAt: DateTime!
}
type Query {
user(id: ID!): User
users(limit: Int, offset: Int): [User!]!
post(id: ID!): Post
}
type Mutation {
createUser(input: CreateUserInput!): User!
createPost(input: CreatePostInput!): Post!
}
input CreateUserInput {
name: String!
email: String!
}
```
## Apollo Server Setup
```javascript
const { ApolloServer } = require('@apollo/server');
const { startStandaloneServer } = require('@apollo/server/standalone');
const resolvers = {
Query: {
user: (_, { id }, { dataSources }) =>
dataSources.userAPI.getUser(id),
users: (_, { limit, offset }, { dataSources }) =>
dataSources.userAPI.getUsers({ limit, offset })
},
User: {
posts: (user, { limit }, { dataSources }) =>
dataSources.postAPI.getPostsByUser(user.id, limit)
},
Mutation: {
createUser: (_, { input }, { dataSources }) =>
dataSources.userAPI.createUser(input)
}
};
const server = new ApolloServer({ typeDefs, resolvers });
```
## DataLoader for N+1 Prevention
```javascript
const DataLoader = require('dataloader');
const userLoader = new DataLoader(async (ids) => {
const users = await User.find({ _id: { $in: ids } });
return ids.map(id => users.find(u => u.id === id));
});
```
## Error Handling
```javascript
const { GraphQLError } = require('graphql');
throw new GraphQLError('User not found', {
extensions: { code: 'NOT_FOUND', argumentName: 'id' }
});
```
## Best Practices
- Use DataLoader to batch queries
- Implement query complexity limits
- Design schema around client needs
- Validate all inputs
- Use descriptive naming conventions
## Python Graphene
See [references/python-graphene.md](references/python-graphene.md) for complete Flask implementation with:
- ObjectType definitions
- Query and Mutation classes
- Input types
- Flask integration
## Best Practices
**Do:**
- Use DataLoader to batch queries
- Implement query complexity limits
- Design schema around client needs
- Validate all inputs
- Use descriptive naming conventions
- Add subscriptions for real-time data
**Don't:**
- Allow deeply nested queries without limits
- Expose database internals
- Ignore N+1 query problems
- Return unauthorized data
- Skip input validation
© secondsky · MIT · secondsky/claude-skills