Overview
Designs complete, production-ready GraphQL schemas including type definitions (scalar, object, input, enum, interface, union), queries, mutations, subscriptions, resolver patterns, solutions to the N+1 problem (DataLoader), pagination (cursor-based), error handling via union types or extensions, and guidance on schema-first vs code-first, stitching vs federation.
When to Use This Skill
- Building a new GraphQL API or refactoring an existing one.
- User describes data model or operations ("users can query their orders with line items and status history").
- Choosing between REST and GraphQL or improving an existing GraphQL schema.
Prerequisites
- GraphQL server (Apollo Server, Yoga, Pothos, Nexus, or codegen-based).
- Database or data sources the resolvers will call.
- For advanced: DataLoader, Redis for caching, understanding of federation.
Steps
Schema-first vs code-first decision:
- Schema-first: SDL + resolvers (good for collaboration with frontend).
- Code-first: TypeScript classes/decorators or builder (better DX, type safety).
Core type system:
- Scalars (ID, String, Int, Float, Boolean, custom DateTime, JSON).
- Enums for status fields.
- Input types for mutations.
- Interfaces and unions for polymorphism.
Query design:
- Root queries should be specific (not generic "node" unless using Relay).
- Always think about what the client actually needs (avoid over-fetching by design).
N+1 problem & DataLoader:
- Identify batchable loads (e.g., user for each post).
- Create DataLoader per type.
- Use in resolvers:
loader.load(id).
Pagination:
- Prefer cursor-based (Relay connection spec or simple
after + first).
- Provide
edges + pageInfo or a simpler items + hasMore.
- Offset pagination only for admin/internal use cases.
Mutations & input validation:
- One mutation per action.
- Return the mutated entity or a payload type.
- Use input objects.
Error handling:
- Use union error types (e.g.,
CreatePostResult = Post | ValidationError | Unauthorized).
- Or GraphQL errors with extensions.
Subscriptions (real-time):
- Use
graphql-ws or Apollo subscriptions.
- Pub/sub backend (Redis, in-memory for dev).
Output:
- Complete SDL or code-first schema.
- Resolver map or class.
- DataLoader setup example.
- Pagination helper.
- Example queries/mutations in the response.
Examples
Full schema for a blog + comments + users (with DataLoader, cursor pagination, and union error types) is provided, along with resolver skeleton and subscription example.
Edge Cases & Error Handling
- Circular references: Use lazy loading or interfaces.
- Authorization: Perform auth checks inside resolvers or with middleware/directives.
- Rate limiting & complexity: Use graphql-query-complexity or persisted queries.
- Schema evolution: Deprecate fields instead of removing; use versioning or federation for major changes.
Verification
- Load the schema in GraphQL Playground / Apollo Studio / Insomnia.
- Run example queries and mutations — they return expected shapes.
- Enable DataLoader batching and confirm single DB query for lists.
- Test pagination cursors with real data.
- Subscriptions fire on mutation.
- Success: Schema is expressive, performant (no N+1), type-safe on both sides, and easy to evolve.
References
Source: Nikoxkx/Agent-Skills — distributed by TomeVault.
1---2name: graphql-schema-designer3description: Designs GraphQL schemas with types, queries, mutations, subscriptions, and resolvers. Use when building or refactoring a GraphQL API. Use when this capability is needed.4---56## Overview78Designs complete, production-ready GraphQL schemas including type definitions (scalar, object, input, enum, interface, union), queries, mutations, subscriptions, resolver patterns, solutions to the N+1 problem (DataLoader), pagination (cursor-based), error handling via union types or extensions, and guidance on schema-first vs code-first, stitching vs federation.910## When to Use This Skill1112- Building a new GraphQL API or refactoring an existing one.13- User describes data model or operations ("users can query their orders with line items and status history").14- Choosing between REST and GraphQL or improving an existing GraphQL schema.1516## Prerequisites1718- GraphQL server (Apollo Server, Yoga, Pothos, Nexus, or codegen-based).19- Database or data sources the resolvers will call.20- For advanced: DataLoader, Redis for caching, understanding of federation.2122## Steps23241. **Schema-first vs code-first decision**:25 - Schema-first: SDL + resolvers (good for collaboration with frontend).26 - Code-first: TypeScript classes/decorators or builder (better DX, type safety).27282. **Core type system**:29 - Scalars (ID, String, Int, Float, Boolean, custom DateTime, JSON).30 - Enums for status fields.31 - Input types for mutations.32 - Interfaces and unions for polymorphism.33343. **Query design**:35 - Root queries should be specific (not generic "node" unless using Relay).36 - Always think about what the client actually needs (avoid over-fetching by design).37384. **N+1 problem & DataLoader**:39 - Identify batchable loads (e.g., user for each post).40 - Create DataLoader per type.41 - Use in resolvers: `loader.load(id)`.42435. **Pagination**:44 - Prefer cursor-based (Relay connection spec or simple `after` + `first`).45 - Provide `edges` + `pageInfo` or a simpler `items` + `hasMore`.46 - Offset pagination only for admin/internal use cases.47486. **Mutations & input validation**:49 - One mutation per action.50 - Return the mutated entity or a payload type.51 - Use input objects.52537. **Error handling**:54 - Use union error types (e.g., `CreatePostResult = Post | ValidationError | Unauthorized`).55 - Or GraphQL errors with extensions.56578. **Subscriptions** (real-time):58 - Use `graphql-ws` or Apollo subscriptions.59 - Pub/sub backend (Redis, in-memory for dev).60619. **Output**:62 - Complete SDL or code-first schema.63 - Resolver map or class.64 - DataLoader setup example.65 - Pagination helper.66 - Example queries/mutations in the response.6768## Examples6970Full schema for a blog + comments + users (with DataLoader, cursor pagination, and union error types) is provided, along with resolver skeleton and subscription example.7172## Edge Cases & Error Handling7374- **Circular references**: Use lazy loading or interfaces.75- **Authorization**: Perform auth checks inside resolvers or with middleware/directives.76- **Rate limiting & complexity**: Use graphql-query-complexity or persisted queries.77- **Schema evolution**: Deprecate fields instead of removing; use versioning or federation for major changes.7879## Verification80811. Load the schema in GraphQL Playground / Apollo Studio / Insomnia.822. Run example queries and mutations — they return expected shapes.833. Enable DataLoader batching and confirm single DB query for lists.844. Test pagination cursors with real data.855. Subscriptions fire on mutation.866. Success: Schema is expressive, performant (no N+1), type-safe on both sides, and easy to evolve.8788## References8990- [GraphQL.js](https://graphql.org/graphql-js/)91- [Apollo Server](https://www.apollographql.com/docs/apollo-server/)92- [Relay Cursor Connections Spec](https://relay.dev/graphql/connections.htm)93- [DataLoader](https://github.com/graphql/dataloader)94- [Pothos GraphQL](https://pothos-graphql.dev/) or [Nexus](https://nexusjs.org/)95- [GraphQL Error Best Practices](https://www.apollographql.com/docs/apollo-server/data/errors/)9697---98> Source: [Nikoxkx/Agent-Skills](https://github.com/Nikoxkx/Agent-Skills) — distributed by [TomeVault](https://tomevault.io).99<!-- tomevault:4.0:skill_md:2026-06-15 -->