GR

Schema-First Architecture

GraphQL schema-first design with code generation and modular SDL composition

Details

Language / Topic
graphqlGraphQL
Category
Architecture

Rules

balanced
- Write `.graphql` SDL files as the schema source of truth and generate TypeScript types with `graphql-code-generator` — never hand-write resolver type signatures.
- Modularize schemas using `extend type Query` across feature modules rather than one monolithic schema file.
- Co-locate resolver implementations with their SDL files: `user/user.graphql`, `user/user.resolver.ts`, `user/user.service.ts`.
- Use `@graphql-tools/merge` to combine SDL documents from multiple modules into a single executable schema at startup.
- Generate resolver type stubs with `graphql-codegen` `typescript-resolvers` plugin — resolvers that miss fields or return wrong types fail at compile time.
- Define a `context` type in `codegen.yml` so all generated resolvers share a typed `Context` interface for dataloaders and authenticated user.
- Keep SDL definitions close to the business domain they represent — avoid placing all types in a flat `schema/` directory as the codebase grows.