编程开发SKILL.md
GraphQL 架构设计
v1组织 Schema、解析器与数据获取方式,分析 GraphQL 接口的一致性和性能。
技能概述
这项技能做什么
组织 Schema、解析器与数据获取方式,分析 GraphQL 接口的一致性和性能。
对应原始技能标识:graphql-architect。本站整理中文说明,技能原文由 Jeffallan/claude-skills 维护。
适用场景与输入
分类:编程开发。建议准备:项目背景、相关代码、语言与依赖版本、期望行为和当前问题。
获取与使用
- 打开固定版本的完整技能目录,按仓库说明获取技能。
- 原目录包含
references等配套资源。请获取完整技能目录,单独下载本站的 SKILL.md 不包含这些文件。 - 在 Claude Code 或具备相应工具能力的兼容 Agent 中加载;兼容 SKILL.md 格式不代表各平台工具完全一致。
- 参照页面的使用示例提供材料,按照原文步骤执行,并核对实际输出。
输出与验证
先说明理解与待确认的问题,再给出实现方案、关键代码和可复现的验证步骤。本站未执行来源仓库中的脚本,也不把示例当作已经完成的运行结果。
来源与许可
- 原始 SKILL.md
- 完整技能目录及配套资源
- 固定提交:
078a25cc5bfd8011459be7b91d004e900c1d02d3 - 许可证:MIT;技能原文和下载内容中保留以下版权与许可说明。
MIT License
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
如何使用这个 Skill
下载 SKILL.md,查看文件中的说明与依赖,再按你的 Agent 支持的方式导入。
SKILL.mdMarkdown · 1 个文件
SKILL.md
---
name: graphql-architect
description: Use when designing GraphQL schemas, implementing Apollo Federation, or building real-time subscriptions. Invoke for schema design, resolvers with DataLoader, query optimization, federation directives.
license: MIT
metadata:
author: https://github.com/Jeffallan
company: https://synergetic.solutions
version: "1.1.0"
domain: api-architecture
triggers: GraphQL, Apollo Federation, GraphQL schema, API graph, GraphQL subscriptions, Apollo Server, schema design, GraphQL resolvers, DataLoader
role: architect
scope: design
output-format: schema
related-skills: api-designer, microservices-architect, database-optimizer
---
# 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
1. **Domain Modeling** - Map business domains to GraphQL type system
2. **Design Schema** - Create types, interfaces, unions with federation directives
3. **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
4. **Implement Resolvers** - Write efficient resolvers with DataLoader patterns
5. **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
6. **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)
```graphql
# 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)
```js
// 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
```js
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:
1. Schema definition (SDL with types and directives)
2. Resolver implementation (with DataLoader patterns)
3. Query/mutation/subscription examples
4. 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
Maintained by [@jeffallan](https://github.com/jeffallan), Principal Consultant at [Synergetic Solutions](https://synergetic.solutions)
[Documentation](https://jeffallan.github.io/claude-skills/skills/api-architecture/graphql-architect/)
---
## Source and license
Original skill: https://github.com/Jeffallan/claude-skills/blob/078a25cc5bfd8011459be7b91d004e900c1d02d3/skills/graphql-architect/SKILL.md
Complete source directory: https://github.com/Jeffallan/claude-skills/tree/078a25cc5bfd8011459be7b91d004e900c1d02d3/skills/graphql-architect
This catalog copy preserves the original instructions. Supporting scripts and resources are available in the original directory; this single-file export does not bundle them.
MIT License
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
使用示例
请使用「GraphQL 架构设计」技能处理下面的任务。 目标:组织 Schema、解析器与数据获取方式,分析 GraphQL 接口的一致性和性能。 输入材料:项目背景、相关代码、语言与依赖版本、期望行为和当前问题。 输出要求:先说明理解与待确认的问题,再给出实现方案、关键代码和可复现的验证步骤。 请先核对所需资料和工具;缺少关键信息时提出具体问题。涉及对外发布、删除或生产环境变更时,先提供可审查的计划,获得授权后再执行。

关注官方公众号
抢先获取热门 Skill 实操干货、产品更新与官方活动资讯。

加入官方交流群
对接创作者与同好,交流技能开发,共建 AI 技能生态。