Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill graphql-implementation -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/graphql-implementation/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/graphql-implementation/

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

Similar skills

Everything for Backend and APIs →

From the same set89

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor