| name | senior-graphql |
| description | GraphQL API design specialist for schema architecture, resolver patterns, federation, and performance optimization |
| license | MIT |
| metadata | {"version":"1.0.0","author":"Claude Skills Team","category":"engineering","domain":"engineering","updated":"2025-12-16T00:00:00.000Z","keywords":["graphql","api","schema","federation","apollo","resolvers","subscriptions","dataloader","performance"],"tech-stack":["GraphQL","Apollo Server","Apollo Federation","DataLoader","TypeScript","Node.js","Prisma"],"python-tools":["schema_analyzer.py","resolver_generator.py","federation_scaffolder.py"]} |
Senior GraphQL Specialist
Expert GraphQL API design and architecture skill for building scalable, type-safe APIs with Apollo Server, Federation, and modern GraphQL patterns.
Overview
This skill provides comprehensive GraphQL development capabilities including schema design, resolver implementation, federation architecture, real-time subscriptions, and performance optimization through DataLoader patterns.
Time Savings: 50%+ reduction in GraphQL API development time through schema generation, resolver scaffolding, and automated federation setup.
Quality Improvement: 40%+ improvement in API consistency through schema-first development, type safety enforcement, and automated best practices.
Core Capabilities
Schema Architecture
- Schema-first design methodology
- Type system design (scalars, enums, interfaces, unions)
- Input type and argument patterns
- Custom directive implementation
- Schema stitching and composition
Resolver Development
- Resolver pattern implementation
- Context and middleware integration
- Authentication/authorization in resolvers
- Error handling and formatting
- N+1 query prevention with DataLoader
Apollo Federation
- Supergraph architecture design
- Subgraph creation and entity definitions
@key, @external, @requires directive usage
- Gateway configuration
- Schema composition validation
Performance Optimization
- Query complexity analysis and limiting
- Depth limiting implementation
- Caching strategies (Apollo Cache, Redis)
- Batching with DataLoader
- Persisted queries
Real-time Features
- Subscription implementation
- WebSocket configuration
- PubSub patterns
- Filtered subscriptions
Quick Start
python scripts/schema_analyzer.py schema.graphql --output json
python scripts/resolver_generator.py schema.graphql --output src/resolvers
python scripts/federation_scaffolder.py users-service --entities User,Profile
Key Workflows
1. Schema-First API Design
Goal: Design a type-safe GraphQL schema following best practices.
Steps:
-
Analyze Requirements
- Identify domain entities and relationships
- Map CRUD operations to queries/mutations
- Define subscription needs for real-time features
-
Design Schema
type User {
id: ID!
email: String!
profile: Profile
posts(first: Int, after: String): PostConnection!
createdAt: DateTime!
}
type PostConnection {
edges: [PostEdge!]!
pageInfo: PageInfo!
totalCount: Int!
}
type PostEdge {
node: Post!
cursor: String!
}
type PageInfo
Boolean
Boolean
String
String
CreateUserInput
String
String
String
user ID User
users Int, String UserConnection
User
createUser CreateUserInput CreateUserPayload
updateUser ID, UpdateUserInput UpdateUserPayload
deleteUser ID DeleteUserPayload
User
postPublished ID Post
Success Criteria:
- Schema passes validation
- All types have descriptions
- Relay pagination implemented for lists
- Input types for all mutations
- Clear naming conventions followed
2. DataLoader Implementation for N+1 Prevention
Goal: Eliminate N+1 queries using DataLoader batching.
Problem Example:
query {
posts {
author {
name
}
}
}
Solution:
-
Create DataLoader Factory
import DataLoader from 'dataloader';
import { prisma } from '../lib/prisma';
export const createLoaders = () => ({
userLoader: new DataLoader<string, User>(async (userIds) => {
const users = await prisma.user.findMany({
where: { id: { in: [...userIds] } }
});
const userMap = new Map(users.map(u => [u.id, u]));
return userIds.map(id => userMap.get(id) || null);
}),
postsByAuthorLoader: new DataLoader<string, Post[]>(async (authorIds) => {
const posts = await prisma.post.findMany({
where: { : { : [...authorIds] } }
});
postMap = <, []>();
posts.( {
existing = postMap.(post.) || [];
existing.(post);
postMap.(post., existing);
});
authorIds.( postMap.(id) || []);
}),
});
= < createLoaders>;
Success Criteria:
- Batch queries visible in logs
- Query count reduced from N+1 to 2
- Response time improved significantly
- DataLoader cache cleared per request
3. Apollo Federation Setup
Goal: Build a federated supergraph from multiple subgraphs.
Architecture:
┌─────────────────────────────────────────────────┐
│ Apollo Gateway │
│ (Schema Composition) │
└─────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Users │ │ Posts │ │ Comments │
│ Subgraph │ │ Subgraph │ │ Subgraph │
└─────────────┘ └─────────────┘ └─────────────┘
Steps:
-
Scaffold Subgraphs
python scripts/federation_scaffolder.py users-service \
--entities User,Profile \
--port 4001
python scripts/federation_scaffolder.py posts-service \
--entities Post \
--references User \
--port 4002
python scripts/federation_scaffolder.py comments-service \
--entities Comment \
--references User,Post \
--port 4003
-
Define Entity References
type User @key(fields: "id") {
id: ID!
email: String!
name: String!
profile: Profile
}
type Post @key(fields: "id") {
id: ID!
title: String!
content: String!
author: User!
}
extend User
ID
Post
Comment
ID
String
User
Post
extend Post
ID
Comment
Success Criteria:
- All subgraphs start without errors
- Schema composition succeeds
- Cross-subgraph queries resolve correctly
- Entity references work bidirectionally
4. Real-time Subscriptions
Goal: Implement GraphQL subscriptions for real-time updates.
Steps:
-
Configure WebSocket Server
import { createServer } from 'http';
import { WebSocketServer } from 'ws';
import { useServer } from 'graphql-ws/lib/use/ws';
import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
const httpServer = createServer(app);
const wsServer = new WebSocketServer({
server: httpServer,
path: '/graphql',
});
const serverCleanup = useServer(
{
schema,
context: (ctx) => ({
user: authenticateWebSocket(ctx.connectionParams),
}),
},
wsServer
);
const server = new ApolloServer({
schema,
plugins: [
ApolloServerPluginDrainHttpServer({ httpServer }),
{
async serverWillStart() {
return {
async drainServer() {
serverCleanup.();
},
};
},
},
],
});
Success Criteria:
- WebSocket connection established
- Subscriptions receive real-time updates
- Filtering works correctly
- Connection cleanup on disconnect
- Production-ready with Redis PubSub
Python Tools
schema_analyzer.py
Purpose: Analyze GraphQL schemas for quality, complexity, and best practices.
Usage:
python scripts/schema_analyzer.py schema.graphql
python scripts/schema_analyzer.py schema.graphql --output json
python scripts/schema_analyzer.py schema.graphql --validate
python scripts/schema_analyzer.py schema.graphql --complexity
Features:
- Type system analysis (types, interfaces, unions, enums)
- Query/mutation/subscription inventory
- Complexity scoring per operation
- Deprecation tracking
- Naming convention validation
- Description coverage checking
- Circular reference detection
resolver_generator.py
Purpose: Generate TypeScript resolvers from GraphQL schema.
Usage:
python scripts/resolver_generator.py schema.graphql --output src/resolvers
python scripts/resolver_generator.py schema.graphql --output src/resolvers --dataloader
python scripts/resolver_generator.py schema.graphql --output src/resolvers --types User,Post
python scripts/resolver_generator.py schema.graphql --output src/resolvers --tests
Generated Output:
- Resolver files per type
- Type definitions
- DataLoader factories
- Context type definitions
- Jest test stubs
federation_scaffolder.py
Purpose: Scaffold Apollo Federation subgraphs with proper entity definitions.
Usage:
python scripts/federation_scaffolder.py users-service --entities User,Profile
python scripts/federation_scaffolder.py posts-service --entities Post --references User
python scripts/federation_scaffolder.py comments-service --entities Comment --docker --port 4003
python scripts/federation_scaffolder.py gateway --subgraphs users:4001,posts:4002,comments:4003
Generated Structure:
service-name/
├── src/
│ ├── schema.graphql # Federation schema
│ ├── resolvers/ # Type resolvers
│ ├── dataloaders/ # DataLoader factories
│ ├── datasources/ # Data access layer
│ └── index.ts # Apollo Server setup
├── tests/ # Jest tests
├── Dockerfile # Container definition
├── docker-compose.yml # Local development
└── package.json
Best Practices
Schema Design
- Use descriptive names (avoid abbreviations)
- Document all types and fields
- Implement Relay-style pagination for lists
- Use input types for mutations
- Return payload types from mutations (not raw types)
- Version breaking changes with new fields (not removal)
Resolver Patterns
- Keep resolvers thin (delegate to services)
- Use DataLoader for all batch-able relations
- Implement proper error handling
- Add authentication at resolver level
- Log slow resolvers for optimization
Federation
- Define clear subgraph boundaries
- Minimize cross-subgraph queries
- Use
@requires sparingly
- Implement proper health checks
- Version subgraph schemas independently
Performance
- Implement query complexity limits
- Use persisted queries in production
- Cache with appropriate TTLs
- Monitor resolver execution time
- Implement query depth limiting
References
Reference Files
references/schema-patterns.md - Schema design patterns and conventions
references/federation-guide.md - Apollo Federation architecture guide
references/performance-optimization.md - GraphQL performance best practices
External Resources
Version: 1.0.0
Last Updated: 2025-12-16
Skill Type: Engineering specialist
Python Tools: 3 (schema_analyzer.py, resolver_generator.py, federation_scaffolder.py)