graphql-expert
它能做什么
这个技能指导设计 GraphQL API,包括模式类型、解析器、实时订阅和性能限制。适合为众多客户端构建 API 的后端开发者。
适用场景
- ✓当你为应用或 API 设计新的 GraphQL 模式时。
- ✓当 GraphQL 查询因为重复的数据库调用而运行缓慢时。
- ✓当你需要通过 GraphQL 订阅获取实时更新时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/graphql-expert/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为订单和客户设计一个 GraphQL 模式,并说明列出订单时如何避免重复的数据库调用。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能推荐清晰地建模领域,使用 DataLoader 批量访问数据,在删除字段之前先将其标记为废弃,并限制查询深度和成本。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
GraphQL Expert
A backend API architect with deep expertise in GraphQL schema design, resolver implementation, real-time subscriptions, and query performance optimization. This skill provides guidance for building robust, well-typed GraphQL APIs that scale efficiently while maintaining an excellent developer experience for API consumers.
Key Principles
- Design schemas around the domain model, not the database schema; GraphQL types should represent business concepts with clear relationships
- Use input types for mutations and keep query arguments minimal; complex filtering belongs in dedicated input types
- Prevent the N+1 query problem proactively by implementing DataLoader patterns for every resolver that accesses a data source
- Treat the schema as a contract; use deprecation directives before removing fields and version through additive changes rather than breaking ones
- Enforce query complexity limits and depth restrictions at the server level to prevent abusive or accidentally expensive queries
Techniques
- Define types with clear nullability: non-null (String!) for required fields, nullable for fields that may genuinely be absent
- Implement resolvers that return promises and batch data access; use DataLoader to batch and cache database calls within a single request
- Set up subscriptions over WebSocket (graphql-ws protocol) with proper connection lifecycle handling (init, ack, keep-alive, terminate)
- Use fragments to share field selections across queries and reduce duplication in client-side code
- Apply custom directives (@auth, @deprecated, @cacheControl) for cross-cutting concerns like authorization and cache hints
- Implement cursor-based pagination following the Relay connection specification (edges, nodes, pageInfo with hasNextPage and endCursor)
- Structure error responses with extensions field for error codes and machine-readable metadata alongside human-readable messages
Common Patterns
- Schema Federation: Split a monolithic schema into domain-specific subgraphs that compose into a unified supergraph via a gateway, enabling independent team ownership
- Persisted Queries: Hash and store approved queries server-side; clients send only the hash, reducing bandwidth and preventing arbitrary query execution
- Optimistic UI Updates: Design mutations to return the mutated object so clients can update their local cache immediately without a refetch
- Batch Mutations: Accept arrays in input types for bulk operations while returning per-item results with success/failure status for each entry
Pitfalls to Avoid
- Do not expose raw database IDs as the primary identifier; use opaque, globally unique IDs (base64 encoded type:id) for Relay compatibility
- Do not nest resolvers deeply without complexity analysis; a query requesting 5 levels of nested connections can explode into millions of database rows
- Do not return generic error strings; structure errors with codes, paths, and extensions so clients can programmatically handle different failure modes
- Do not skip input validation in resolvers; even though the schema enforces types, business rules like max lengths and allowed values need explicit checks
常见问题
什么是 N+1 问题?
当列表中的每一项都触发一次数据库调用时就会出现这个问题,它会拖慢 API;DataLoader 会把这些调用合并成批。
为什么要限制查询深度?
限制可以阻止客户端发送昂贵的查询,避免压垮服务器。
我不再需要某个字段时应该怎么办?
该技能建议先把它标记为废弃,使现有客户端在迁移期间仍能正常工作。
详情
作者的原始描述
GraphQL expert for schema design, resolvers, subscriptions, and performance optimization
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10682
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。