1---2name: urigo-accounter-fullstack-graphql-module3description: GraphQL Module Patterns4---56# GraphQL Module Patterns78## Module Anatomy910Each module in `src/modules/<name>/` contains:1112- `typeDefs/<name>.graphql.ts` — schema using `gql` tag from `graphql-modules`13- `resolvers/<name>.resolver.ts` — query, mutation, and field resolvers14- `providers/<name>.provider.ts` — data access layer with `@Injectable()`15- `helpers/` — module-specific utility functions16- `types.ts` — re-exports generated types from `__generated__/`17- `index.ts` — `createModule()` registration1819See `references/` for annotated examples of each file.2021## Provider Injection2223- Providers use `@Injectable({ scope: Scope.Operation, global: true })` from `graphql-modules`24- Constructor injection for dependencies: `constructor(private db: TenantAwareDBClient, ...)`25- Database access via `TenantAwareDBClient` (tenant-scoped) — never raw Postgres clients26- Admin context via `AdminContextProvider` when owner/tenant ID is needed2728## SQL Queries (PgTyped — mandatory)2930- **Avoid inline SQL** with raw pg or tagged strings without a type parameter.31- All SQL better use `sql<IQueryType>` from `@pgtyped/runtime`, defined as module-level constants32 **outside** the class.33- The `IQueryType` interface is generated by `yarn generate` from the SQL — never hand-write it.34- Call queries via `.run(params, this.db)` inside provider methods.35- See `references/example-provider.ts` for the correct pattern.3637## DataLoader for N+1 Prevention3839- Every provider that fetches by ID must expose a DataLoader40 (`new DataLoader(keys => this.batchFn(keys))`)41- Batch function receives `readonly` array of keys, returns results in matching order42- Prime the loader cache when fetching all records (e.g., `getAll` primes individual loaders)43- Call `clearAll()` on loaders after mutations to invalidate cache4445## Field Resolvers4647- Field resolvers on extended types resolve cross-module relationships48- Access the parent's DB fields (snake_case) to load related data via providers49- Return `null` explicitly when the foreign key is missing — don't throw5051## Type Generation5253- Types come from `__generated__/types.ts` (graphql-codegen) and `__generated__/<name>.types.ts`54 (pgtyped)55- Module resolver type: `<ModuleName>Module.Resolvers` from `./types.js`56- Never hand-write GraphQL resolver types — always import generated ones57- Run `yarn generate` after any schema or SQL change5859## Gotchas6061- Always import with `.js` extension — even for `.ts` source files (ESM requirement)62- Never access DB directly from resolvers — always go through providers63- `__generated__/` is git-ignored — run `yarn generate` before working on a module for the first64 time65- Provider classes must have `@Injectable()` decorator or DI fails silently at runtime66- SQL queries use `@pgtyped/runtime`'s `sql` tagged template — types are generated from the SQL, not67 hand-written68- Auth directives (`@requiresAuth`, `@requiresAnyRole`) go on schema fields, not in resolver code69- `Scope.Operation` ensures one provider instance per GraphQL operation (request-scoped)7071---72> Source: [Urigo/accounter-fullstack](https://github.com/Urigo/accounter-fullstack) — distributed by [TomeVault](https://tomevault.io).73<!-- tomevault:4.0:skill_md:2026-06-15 -->
Run npx skillmds@latest add tomevault-io/urigo-accounter-fullstack-graphql-module in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
GraphQL Module Patterns It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.