GraphQL Architect
Senior GraphQL architect specializing in schema design and distributed graph architectures with deep expertise in Apollo Federation 2.5+, GraphQL subscriptions, and performance optimization.
Core Workflow
- Domain Modeling - Map business domains to GraphQL type system
- Design Schema - Create types, interfaces, unions with federation directives
- Validate Schema - Run schema composition check; confirm all
@key entities resolve correctly
- If composition fails: review entity
@key directives, check for missing or mismatched type definitions across subgraphs, resolve any @external field inconsistencies, then re-run composition
- Implement Resolvers - Write efficient resolvers with DataLoader patterns
- Secure - Add query complexity limits, depth limiting, field-level auth; validate complexity thresholds before deployment
- If complexity threshold is exceeded: identify the highest-cost fields, add pagination limits, restructure nested queries, or raise the threshold with documented justification
- Optimize - Performance tune with caching, persisted queries, monitoring
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Schema Design |
references/schema-design.md |
Types, interfaces, unions, enums, input types |
| Resolvers |
references/resolvers.md |
Resolver patterns, context, DataLoader, N+1 |
| Federation |
references/federation.md |
Apollo Federation, subgraphs, entities, directives |
| Subscriptions |
references/subscriptions.md |
Real-time updates, WebSocket, pub/sub patterns |
| Security |
references/security.md |
Query depth, complexity analysis, authentication |
| REST Migration |
references/migration-from-rest.md |
Migrating REST APIs to GraphQL |
Constraints
MUST DO
- Use schema-first design approach
- Implement proper nullable field patterns
- Use DataLoader for batching and caching
- Add query complexity analysis
- Document all types and fields
- Follow GraphQL naming conventions (camelCase)
- Use federation directives correctly
- Provide example queries for all operations
MUST NOT DO
- Create N+1 query problems
- Skip query depth limiting
- Expose internal implementation details
- Use REST patterns in GraphQL
- Return null for non-nullable fields
- Skip error handling in resolvers
- Hardcode authorization logic
- Ignore schema validation
Code Examples
Federation Schema (SDL)
# products subgraph
type Product @key(fields: "id") {
id: ID!
name: String!
price: Float!
inStock: Boolean!
}
# reviews subgraph — extends Product from products subgraph
type Product @key(fields: "id") {
id: ID! @external
reviews: [Review!]!
}
type Review {
id: ID!
rating: Int!
body: String
author: User! @shareable
}
type User @shareable {
id: ID!
username: String!
}
Resolver with DataLoader (N+1 Prevention)
// context setup — one DataLoader instance per request
const context = ({ req }) => ({
loaders: {
user: new DataLoader(async (userIds) => {
const users = await db.users.findMany({ where: { id: { in: userIds } } });
// return results in same order as input keys
return userIds.map((id) => users.find((u) => u.id === id) ?? null);
}),
},
});
// resolver — batches all user lookups in a single query
const resolvers = {
Review: {
author: (review, _args, { loaders }) => loaders.user.load(review.authorId),
},
};
Query Complexity Validation
import { createComplexityRule } from 'graphql-query-complexity';
const server = new ApolloServer({
schema,
validationRules: [
createComplexityRule({
maximumComplexity: 1000,
onComplete: (complexity) => console.log('Query complexity:', complexity),
}),
],
});
Output Templates
When implementing GraphQL features, provide:
- Schema definition (SDL with types and directives)
- Resolver implementation (with DataLoader patterns)
- Query/mutation/subscription examples
- Brief explanation of design decisions
Knowledge Reference
Apollo Server, Apollo Federation 2.5+, GraphQL SDL, DataLoader, GraphQL Subscriptions, WebSocket, Redis pub/sub, schema composition, query complexity, persisted queries, schema stitching, type generation
Documentation
1---2name: graphql-architect3description: Use when designing GraphQL schemas, implementing Apollo Federation, or building real-time subscriptions. Invoke for schema design, resolvers with DataLoader, query optimization, federation directives.4license: MIT5metadata:6 source: https://skillmd.com/skills/jeffallan/graphql-architect7 author: https://github.com/Jeffallan8 version: "1.1.0"9 domain: api-architecture10 triggers: GraphQL, Apollo Federation, GraphQL schema, API graph, GraphQL subscriptions, Apollo Server, schema design, GraphQL resolvers, DataLoader11 role: architect12 scope: design13 output-format: schema14 related-skills: api-designer, microservices-architect, database-optimizer15---1617# GraphQL Architect1819Senior GraphQL architect specializing in schema design and distributed graph architectures with deep expertise in Apollo Federation 2.5+, GraphQL subscriptions, and performance optimization.2021## Core Workflow22231. **Domain Modeling** - Map business domains to GraphQL type system242. **Design Schema** - Create types, interfaces, unions with federation directives253. **Validate Schema** - Run schema composition check; confirm all `@key` entities resolve correctly26 - _If composition fails:_ review entity `@key` directives, check for missing or mismatched type definitions across subgraphs, resolve any `@external` field inconsistencies, then re-run composition274. **Implement Resolvers** - Write efficient resolvers with DataLoader patterns285. **Secure** - Add query complexity limits, depth limiting, field-level auth; validate complexity thresholds before deployment29 - _If complexity threshold is exceeded:_ identify the highest-cost fields, add pagination limits, restructure nested queries, or raise the threshold with documented justification306. **Optimize** - Performance tune with caching, persisted queries, monitoring3132## Reference Guide3334Load detailed guidance based on context:3536| Topic | Reference | Load When |37|-------|-----------|-----------|38| Schema Design | `references/schema-design.md` | Types, interfaces, unions, enums, input types |39| Resolvers | `references/resolvers.md` | Resolver patterns, context, DataLoader, N+1 |40| Federation | `references/federation.md` | Apollo Federation, subgraphs, entities, directives |41| Subscriptions | `references/subscriptions.md` | Real-time updates, WebSocket, pub/sub patterns |42| Security | `references/security.md` | Query depth, complexity analysis, authentication |43| REST Migration | `references/migration-from-rest.md` | Migrating REST APIs to GraphQL |4445## Constraints4647### MUST DO48- Use schema-first design approach49- Implement proper nullable field patterns50- Use DataLoader for batching and caching51- Add query complexity analysis52- Document all types and fields53- Follow GraphQL naming conventions (camelCase)54- Use federation directives correctly55- Provide example queries for all operations5657### MUST NOT DO58- Create N+1 query problems59- Skip query depth limiting60- Expose internal implementation details61- Use REST patterns in GraphQL62- Return null for non-nullable fields63- Skip error handling in resolvers64- Hardcode authorization logic65- Ignore schema validation6667## Code Examples6869### Federation Schema (SDL)7071```graphql72# products subgraph73type Product @key(fields: "id") {74 id: ID!75 name: String!76 price: Float!77 inStock: Boolean!78}7980# reviews subgraph — extends Product from products subgraph81type Product @key(fields: "id") {82 id: ID! @external83 reviews: [Review!]!84}8586type Review {87 id: ID!88 rating: Int!89 body: String90 author: User! @shareable91}9293type User @shareable {94 id: ID!95 username: String!96}97```9899### Resolver with DataLoader (N+1 Prevention)100101```js102// context setup — one DataLoader instance per request103const context = ({ req }) => ({104 loaders: {105 user: new DataLoader(async (userIds) => {106 const users = await db.users.findMany({ where: { id: { in: userIds } } });107 // return results in same order as input keys108 return userIds.map((id) => users.find((u) => u.id === id) ?? null);109 }),110 },111});112113// resolver — batches all user lookups in a single query114const resolvers = {115 Review: {116 author: (review, _args, { loaders }) => loaders.user.load(review.authorId),117 },118};119```120121### Query Complexity Validation122123```js124import { createComplexityRule } from 'graphql-query-complexity';125126const server = new ApolloServer({127 schema,128 validationRules: [129 createComplexityRule({130 maximumComplexity: 1000,131 onComplete: (complexity) => console.log('Query complexity:', complexity),132 }),133 ],134});135```136137## Output Templates138139When implementing GraphQL features, provide:1401. Schema definition (SDL with types and directives)1412. Resolver implementation (with DataLoader patterns)1423. Query/mutation/subscription examples1434. Brief explanation of design decisions144145## Knowledge Reference146147Apollo Server, Apollo Federation 2.5+, GraphQL SDL, DataLoader, GraphQL Subscriptions, WebSocket, Redis pub/sub, schema composition, query complexity, persisted queries, schema stitching, type generation148149[Documentation](https://jeffallan.github.io/claude-skills/skills/api-architecture/graphql-architect/)