# graphql-performance-optimizer

A subagent that digs into slow GraphQL queries: finds N+1 patterns, wires up DataLoader, sets caching. Useful when a user list page drags for seconds.

- subagent · `type=agent` · Claude Code · 599 installs
- Author: davila7
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/agents/api-graphql/graphql-performance-optimizer.md
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/agents/graphql-performance-optimizer

## What it does

The subagent works on existing code. It reads resolver files, spots per-record database calls and rewrites them to batched loading with DataLoader. The schema stays untouched. It can also turn on Automatic Persisted Queries in Apollo Server, point APQ at a Redis store and add field-level cache-control so a CDN serves the short GET responses.

Federated graphs get a different set of moves: query plan caching at the router, DataLoader instances scoped to each request context, and batch loading through `__resolveReference` for entities. That collapses the cross-subgraph fetches behind high p95 latency.

Its tools are `Read`, `Grep`, `Glob`, `Edit`, `Write`, `Bash`, the model is `sonnet`, and the permission mode is `acceptEdits`. It edits files on its own, so keep the project under git before you run it. One caveat: security work — query allowlisting, authorization caching, introspection control — is out of scope, that belongs to `graphql-security-specialist`.

## Install

### Claude Code (native platform)

1. **claude-code-templates**
```bash
npx claude-code-templates@latest --agent api-graphql/graphql-performance-optimizer
```

2. **Manually: put the files in place**
- File: `.claude/agents/graphql-performance-optimizer.md` — For all projects use ~/.claude/agents/. Claude delegates by the description field or an @-mention

### Codex

**Manually: put the files in place**
- File: `.codex/agents/graphql-performance-optimizer.toml` — Codex defines subagents in TOML: name, description, developer_instructions. Move the Markdown text into developer_instructions by hand. For all projects use ~/.codex/agents/

### Cursor

**Manually: put the files in place**
- File: `.cursor/agents/graphql-performance-optimizer.md` — Cursor also reads .claude/agents/

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/agents/api-graphql/graphql-performance-optimizer.md

## When to use it
- find an N+1 in a resolver and rewrite it with DataLoader
- cut origin hits on a public API
- cache the query plan in a federated graph
- drop the extra `SELECT COUNT(*)` behind connection fields
- compare query counts before and after a fix

## Example prompts
- Find the N+1 in our user list resolvers and rewrite them with DataLoader
- Set up APQ and CDN caching for our Apollo Server
- Add router query plan caching and batch entity loading

## Similar
- [graphql-implementation](https://affpapa.org/en/nevibecode/skills/graphql-implementation.md) — skill · 380 installs
- [apollo-graphql](https://affpapa.org/en/nevibecode/skills/apollo-graphql.md) — skill · 677 installs
- [graphql-architect](https://affpapa.org/en/nevibecode/agents/graphql-architect.md) — subagent · 1038 installs
- [neo4j-graphql-skill](https://affpapa.org/en/nevibecode/skills/neo4j-graphql-skill.md) — skill · 809 installs
- [graphql-schema](https://affpapa.org/en/nevibecode/skills/graphql-schema.md) — skill · 4000 installs
- [graphql-operations](https://affpapa.org/en/nevibecode/skills/graphql-operations.md) — skill · 3600 installs

From the same set: [davila7/claude-code-templates](https://affpapa.org/en/nevibecode/by/davila7/claude-code-templates.md) — 205 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
