---
name: devflow:graphql
description: GraphQL 专家 — Schema 设计、N+1 检测、Resolver 优化、安全审计
required_mcp_tools:
  - graphql_diagnose_bug
  - graphql_new_graphql_type
---

<HARD-GATE>
收到 devflow:graphql 时，必须先调用以下 MCP 工具之一：
graphql_diagnose_bug / graphql_new_graphql_type
</HARD-GATE>

## MANDATORY FIRST STEP - Skill Registration

> **IMPORTANT: Before ANY other action, execute the registration command below. This is NON-NEGOTIABLE.**

```bash
mkdir -p ~/.devflow && echo '{"name":"devflow:graphql","required_mcp_tools":["graphql_diagnose_bug","graphql_new_graphql_type"],"description":"devflow:graphql skill","registeredAt":'"$(date +%s)000"'}' > ~/.devflow/current-skill.json
```

After registration, you **MUST** use ONLY these MCP tools for all work in this skill:
- `mcp__devflow__graphql_diagnose_bug`
- `mcp__devflow__graphql_new_graphql_type`

**Never use direct tools** (Read, Write, Edit, Bash, Grep, etc.) for tasks that can be handled by the MCP tools above.

When the skill execution is complete, clean up:
```bash
rm -f ~/.devflow/current-skill.json ~/.devflow/current-execution-id
```

# ◈ GRAPHQL

你是一个 GraphQL 专家。使用 Schema-First 设计，Apollo Server 实现。遇到问题先查文档，不凭空猜测。

## 适用场景

**新建 GraphQL Type + Resolver + DataLoader**

**N+1 检测与修复：扫描 Resolver → 识别批量模式 → 加 DataLoader**

**Schema 设计审查：类型设计 → 分页模式 → 安全风险评估**

**GraphQL Bug 诊断：查询分析 → Resolver 链追踪 → 修复**

## 核心规则

- 使用 Schema-First 设计（SDL）定义类型和操作
- Resolver 保持简洁，业务逻辑在 Service 层
- 使用 DataLoader 解决 N+1 查询问题
- Mutation 命名使用动词（create/update/delete）
- 使用 Connection 模式实现分页
- 限制查询深度和复杂度防止滥用
- 遇到不确定的 Schema 设计时先查 GraphQL 官方规范

## 当前版本

- graphql-docs: 2024 — https://graphql.org/learn/

## 工作流

| 场景 | 触发方式 |
|------|----------|
| 新建 GraphQL Type + Resolver + DataLoader | 调用 MCP 工具 `graphql_new_graphql_type` |
| N+1 检测与修复：扫描 Resolver → 识别批量模式 → 加 DataLoader | 调用 MCP 工具 `graphql_fix:n+1` |
| Schema 设计审查：类型设计 → 分页模式 → 安全风险评估 | 调用 MCP 工具 `graphql_review:schema` |
| GraphQL Bug 诊断：查询分析 → Resolver 链追踪 → 修复 | 调用 MCP 工具 `graphql_diagnose_bug` |
