Home › GraphQL › GraphQL server (Apollo) rules

GraphQL server (Apollo) rules

Cursor rules for schema-first GraphQL servers with Apollo Server, codegen types, DataLoader, and safe errors.

CursorGraphQL

How to use

Save this as .cursor/rules/graphql.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.cursor/rules/graphql.mdcDownload  
---
description: GraphQL server (Apollo) conventions
globs: ["src/**/*.{ts,graphql}"]
alwaysApply: false
---

# GraphQL server (Apollo)

- Schema-first: edit `.graphql` files in `src/schema/`, then run `npm run codegen` (GraphQL Code Generator) to get resolver types. Resolvers are typed with the generated `Resolvers` type.
- Naming: types `PascalCase`, fields `camelCase`, enums `SCREAMING_SNAKE`. Mutations are verbs (`createPost`) taking one `input:` argument and returning a payload type.
- Lists that can grow use cursor pagination (`first`, `after`, `edges`, `pageInfo`).
- Resolvers stay thin: get the user and loaders from `context`, call a service.
- Batch every field that loads by id with DataLoader created per request in the context factory. No DB call inside a list item resolver without a loader.
- Authorization in the service or a directive, checked per field when data is sensitive; not only at the top-level query.
- Expected errors are `GraphQLError` with `extensions.code` (`UNAUTHENTICATED`, `FORBIDDEN`, `BAD_USER_INPUT`). Mask unexpected errors in production.
- Protect the server: depth/complexity limits, disable introspection in production if the API is private, persisted queries for public clients.
- Deprecate with `@deprecated(reason: ...)` instead of removing fields.

## Don't
- Don't change a field's type or nullability in place; add a new field.

## Done when
Codegen is clean, `tsc --noEmit` and resolver tests pass.

More: all GraphQL rules · all Cursor rules

Related rules

Cloudflare Agents SDK rules

Cursor rules for stateful AI agents on Cloudflare (agents package): Durable Object state, SQL, scheduling, and WebSockets.

CursorCloudflare Workers / Hono

Django Ninja API rules

Cursor rules for Django Ninja APIs on Django 5.2: routers, Pydantic schemas, auth, async views, and tests.

CursorDjango

Django REST Framework rules

Cursor rules for Django 5 + Django REST Framework APIs: serializers, viewsets, permissions, and query performance.

CursorDjango

Fastify 5 API rules

Cursor rules for Fastify 5 APIs in TypeScript: plugins and encapsulation, JSON schema validation, hooks, and inject tests.

CursorNode.js / TypeScript

Go gRPC service rules

Cursor rules for gRPC services in Go with protobuf, buf for codegen and linting, interceptors, and status errors.

CursorGo

Hono on Cloudflare Workers rules

Cursor rules for Hono 4 APIs on Cloudflare Workers with Wrangler, typed bindings, D1, KV, and Vitest.

CursorCloudflare Workers / Hono

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.