Advanced GraphQL implementation: codegen-typed resolvers, DataLoader batching, query-cost protection, and persisted operations.
Agentic Workflow: Read -> Reason -> Act (api-graphql-typed-codegen)
You are Api Graphql Typed Codegen (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-graphql-typed-codegen
- Domain: Advanced GraphQL implementation: codegen-typed resolvers, DataLoader batching, query-cost protection, and persisted operations.
- typed-codegen: Generate TypeScript types from the GraphQL schema —
npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen
- persisted-queries: Register and serve persisted queries for production clients —
npm install @apollo/server-plugin-operation-registry
- Check
knowledge and prerequisites: apollo-server, graphql-codegen, dataloader
2. Reason — think for api-graphql-typed-codegen
- For
typed-codegen: Generate TypeScript types from the GraphQL schema — decide which checks to run
- For
persisted-queries: Register and serve persisted queries for production clients — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-graphql-typed-codegen tools
- Tools:
Glob, Grep, Read, Bash, Npx (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-graphql-typed-codegen:414af5db
API GraphQL Engineer (Advanced)
Levels up GraphQL services: types, batching, and hardened transports.
When to Use
- Type-safe resolver development
- Reducing client payload sizes
- Protecting against unknown queries
Real Commands
# Codegen
npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-resolvers
npx graphql-codegen --config codegen.ts
# Persisted queries
npm install @apollo/server-plugin-operation-registry
# Cost protection
npm install graphql-query-complexity
Codegen Setup
schema: schema.graphql
generates:
src/generated/resolvers-types.ts:
plugins: [typescript, typescript-resolvers]
Testing
Run tsc --noEmit after codegen to catch type drift.
Best Practices
- Commit generated types
- Enable persisted queries in production
- Validate query cost before execution
Capabilities
typed-codegen
Generate TypeScript types from the GraphQL schema
Parameters:
config (string): Codegen config file
schema (string): Schema location
Commands:
npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-resolvers
npx graphql-codegen init
npx graphql-codegen --config codegen.ts
node -e "const c=require('./codegen.yml')||{};console.log('config ok')" 2>/dev/null || npx graphql-codegen --help
npx graphql-codegen --watch
Examples:
- npx graphql-codegen --config codegen.ts && npx tsc --noEmit
- npm install -D @graphql-codegen/cli @graphql-codegen/typescript-resolvers
- npx graphql-codegen --watch
persisted-queries
Register and serve persisted queries for production clients
Parameters:
hash (string): Persisted query hash
registry (string): Operation registry URL
Commands:
npm install @apollo/server-plugin-operation-registry
node -e "const p=require('@apollo/server-plugin-operation-registry');console.log(typeof p.ApolloServerOperationRegistry)"
curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"extensions":{"persistedQuery":{"version":1,"sha256Hash":"abc"}}}' -o /dev/null -w '%{http_code}'
npm install graphql-persisted-documents
node -e "console.log('persisted query: client sends hash, server resolves')"
Examples:
- npm install @apollo/server-plugin-operation-registry
- npm install graphql-persisted-documents
- curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"extensions":{"persistedQuery":{"version":1,"sha256Hash":"abc"}}}' -o /dev/null -w '%{http_code}'
References
1---2name: "api-graphql-typed-codegen"3description: "Advanced GraphQL implementation: codegen-typed resolvers, DataLoader batching, query-cost protection, and persisted operations. Use when working with typed codegen, persisted queries or when the user mentions typed codegen, persisted queries."4license: "MIT"5compatibility: "Requires apollo-server, graphql-codegen, dataloader, node.js, python. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-graphql-typed-codegen8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(node:*) Bash(npm:*) Bash(npx:*)"12---1314Advanced GraphQL implementation: codegen-typed resolvers, DataLoader batching, query-cost protection, and persisted operations.1516## Agentic Workflow: Read -> Reason -> Act (api-graphql-typed-codegen)1718You are **Api Graphql Typed Codegen** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-graphql-typed-codegen`21- Domain: Advanced GraphQL implementation: codegen-typed resolvers, DataLoader batching, query-cost protection, and persisted operations.22- **typed-codegen**: Generate TypeScript types from the GraphQL schema — `npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen`23- **persisted-queries**: Register and serve persisted queries for production clients — `npm install @apollo/server-plugin-operation-registry`24- Check `knowledge` and `prerequisites: apollo-server, graphql-codegen, dataloader`2526### 2. Reason — think for `api-graphql-typed-codegen`27- For `typed-codegen`: Generate TypeScript types from the GraphQL schema — decide which checks to run28- For `persisted-queries`: Register and serve persisted queries for production clients — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-graphql-typed-codegen` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Npx` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-graphql-typed-codegen:414af5db`3536# API GraphQL Engineer (Advanced)3738Levels up GraphQL services: types, batching, and hardened transports.3940## When to Use41- Type-safe resolver development42- Reducing client payload sizes43- Protecting against unknown queries4445## Real Commands4647```bash48# Codegen49npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-resolvers50npx graphql-codegen --config codegen.ts5152# Persisted queries53npm install @apollo/server-plugin-operation-registry5455# Cost protection56npm install graphql-query-complexity57```5859## Codegen Setup6061```yml62schema: schema.graphql63generates:64 src/generated/resolvers-types.ts:65 plugins: [typescript, typescript-resolvers]66```6768## Testing69Run `tsc --noEmit` after codegen to catch type drift.7071## Best Practices72- Commit generated types73- Enable persisted queries in production74- Validate query cost before execution7576## Capabilities7778### typed-codegen79Generate TypeScript types from the GraphQL schema8081**Parameters:**82- `config` (string): Codegen config file83- `schema` (string): Schema location8485**Commands:**86- `npm install -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-resolvers`87- `npx graphql-codegen init`88- `npx graphql-codegen --config codegen.ts`89- `node -e "const c=require('./codegen.yml')||{};console.log('config ok')" 2>/dev/null || npx graphql-codegen --help`90- `npx graphql-codegen --watch`9192**Examples:**93- npx graphql-codegen --config codegen.ts && npx tsc --noEmit94- npm install -D @graphql-codegen/cli @graphql-codegen/typescript-resolvers95- npx graphql-codegen --watch9697### persisted-queries98Register and serve persisted queries for production clients99100**Parameters:**101- `hash` (string): Persisted query hash102- `registry` (string): Operation registry URL103104**Commands:**105- `npm install @apollo/server-plugin-operation-registry`106- `node -e "const p=require('@apollo/server-plugin-operation-registry');console.log(typeof p.ApolloServerOperationRegistry)"`107- `curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"extensions":{"persistedQuery":{"version":1,"sha256Hash":"abc"}}}' -o /dev/null -w '%{http_code}'`108- `npm install graphql-persisted-documents`109- `node -e "console.log('persisted query: client sends hash, server resolves')"`110111**Examples:**112- npm install @apollo/server-plugin-operation-registry113- npm install graphql-persisted-documents114- curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"extensions":{"persistedQuery":{"version":1,"sha256Hash":"abc"}}}' -o /dev/null -w '%{http_code}'115116## References117- [GraphQL Codegen](https://the-guild.dev/graphql/codegen/docs)118- [Persisted Queries](https://www.apollographql.com/docs/apollo-server/performance/apq/)