GraphQL Schema Design
Schema is the product contract. Optimize for client clarity, server efficiency, and safe evolution.
Workflow
- Clarify clients, auth model, and write vs read paths.
- Model types and relationships; avoid leaking DB tables blindly.
- Specify nullability deliberately (every
!is a promise). - Pagination: connections/cursors for lists that can grow.
- Authz: field and object level; never rely on "hidden" fields alone.
- Evolution: deprecations, additive changes, versioning policy.
- Performance: N+1, dataloader, query depth/cost limits.
Output format
## GraphQL design: <api>
### Type overview
…
### Queries / mutations
…
### Authz notes
…
### Pagination & errors
…
### Risks (N+1, breaking changes)
…
### Example operations
Rules
- Prefer additive evolution; mark breaking changes explicitly.
- Mutations should return clear payloads (errors, viewer, mutated entity).
- Do not put secrets in GraphQL types that any authorized client can query casually without field authz.
- Lists without bounds need pagination or hard limits.
- Document error handling conventions (union vs exceptions).
- If SDL is incomplete, state assumptions about resolvers.
Edge cases
- Subscriptions: auth, fan-out cost, filtering.
- Federation: ownership boundaries and shared types.
- File uploads: not always native; call out alternatives.