# GraphQL 变更操作返回 HTTP 400，附带 errors 数组

- **ID:** `api/graphql-http-status-400-mutation-returned-errors`
- **领域:** api
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

GraphQL 端点会在变更操作验证或执行失败时返回 HTTP 400，即使请求本身是语法有效的 JSON。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| graphql-js v16.8 | active | — | — |
| apollo-server v4.6 | active | — | — |
| express-graphql v0.12 | active | — | — |

## 解决方案

1. ```
   In the client, check for errors array in response body even on 400, not just 200.
   ```
2. ```
   Use a GraphQL client like Apollo that handles non-200 responses gracefully.
   ```

## 无效尝试

- **** — The request body is usually valid JSON; the error is in the mutation logic, not parsing. (75% 失败率)
- **** — Logging alone doesn't fix the underlying mutation error; only masks symptoms. (60% 失败率)
- **** — GraphQL spec allows 400 for business logic errors; headers are irrelevant. (80% 失败率)
