api
protocol_error
ai_generated
true
GraphQL端点返回HTTP 200但包含错误数组
GraphQL endpoint returned HTTP 200 with errors array
ID: api/graphql-http-status-200-with-errors
80%修复率
85%置信度
1证据数
2024-03-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| [email protected] | active | — | — | — |
| Apollo Server 4.9.0 | active | — | — | — |
| Apollo Client 3.8.0 | active | — | — | — |
| graphql-yoga 5.0.0 | active | — | — | — |
根因分析
GraphQL规范允许部分成功——当某些解析器失败但传输成功时,响应体包含errors键且HTTP状态码为200。
English
GraphQL specification allows partial success — HTTP 200 with errors key in response body when some resolvers fail but transport succeeds.
官方文档
https://spec.graphql.org/June2018/#sec-Errors解决方案
-
在Apollo Client中设置errorPolicy为'all'以显示错误:new ApolloClient({ uri: '/graphql', errorPolicy: 'all' }) -
手动解析响应体:const { data, errors } = await response.json(); if (errors) { console.error('GraphQL errors:', errors); } -
使用中间件检查GraphQL响应中的错误,如果存在则抛出异常
无效尝试
常见但无效的做法:
-
75% 失败
Checking only HTTP status code (200) without parsing response body for errors field
-
60% 失败
Assuming all 200 responses are successful and ignoring errors array entirely
-
80% 失败
Setting Apollo Client errorPolicy to 'ignore' which silently discards errors