api
protocol_error
ai_generated
true
GraphQL endpoint returned HTTP 200 with errors array
ID: api/graphql-http-status-200-with-errors
80%Fix Rate
85%Confidence
1Evidence
2024-03-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| [email protected] | active | — | — | — |
| Apollo Server 4.9.0 | active | — | — | — |
| Apollo Client 3.8.0 | active | — | — | — |
| graphql-yoga 5.0.0 | active | — | — | — |
Root Cause
GraphQL specification allows partial success — HTTP 200 with errors key in response body when some resolvers fail but transport succeeds.
generic中文
GraphQL规范允许部分成功——当某些解析器失败但传输成功时,响应体包含errors键且HTTP状态码为200。
Official Documentation
https://spec.graphql.org/June2018/#sec-ErrorsWorkarounds
-
90% success In Apollo Client, set errorPolicy to 'all' to surface errors: new ApolloClient({ uri: '/graphql', errorPolicy: 'all' })
In Apollo Client, set errorPolicy to 'all' to surface errors: new ApolloClient({ uri: '/graphql', errorPolicy: 'all' }) -
85% success Parse response body manually: const { data, errors } = await response.json(); if (errors) { console.error('GraphQL errors:', errors); }
Parse response body manually: const { data, errors } = await response.json(); if (errors) { console.error('GraphQL errors:', errors); } -
80% success Use a middleware to check for errors in GraphQL responses and throw if any exist
Use a middleware to check for errors in GraphQL responses and throw if any exist
中文步骤
在Apollo Client中设置errorPolicy为'all'以显示错误:new ApolloClient({ uri: '/graphql', errorPolicy: 'all' })手动解析响应体:const { data, errors } = await response.json(); if (errors) { console.error('GraphQL errors:', errors); }使用中间件检查GraphQL响应中的错误,如果存在则抛出异常
Dead Ends
Common approaches that don't work:
-
75% fail
Checking only HTTP status code (200) without parsing response body for errors field
-
60% fail
Assuming all 200 responses are successful and ignoring errors array entirely
-
80% fail
Setting Apollo Client errorPolicy to 'ignore' which silently discards errors