# GraphQL端点返回HTTP 200但包含错误数组

- **ID:** `api/graphql-http-status-200-with-errors`
- **领域:** api
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

GraphQL规范允许部分成功——当某些解析器失败但传输成功时，响应体包含errors键且HTTP状态码为200。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| graphql-js@16.8.0 | active | — | — |
| Apollo Server 4.9.0 | active | — | — |
| Apollo Client 3.8.0 | active | — | — |
| graphql-yoga 5.0.0 | active | — | — |

## 解决方案

1. ```
   在Apollo Client中设置errorPolicy为'all'以显示错误：new ApolloClient({ uri: '/graphql', errorPolicy: 'all' })
   ```
2. ```
   手动解析响应体：const { data, errors } = await response.json(); if (errors) { console.error('GraphQL errors:', errors); }
   ```
3. ```
   使用中间件检查GraphQL响应中的错误，如果存在则抛出异常
   ```

## 无效尝试

- **** — Checking only HTTP status code (200) without parsing response body for errors field (75% 失败率)
- **** — Assuming all 200 responses are successful and ignoring errors array entirely (60% 失败率)
- **** — Setting Apollo Client errorPolicy to 'ignore' which silently discards errors (80% 失败率)
