知识卡片
响应分别承载数据与错误
GraphQL 响应以 data 承载查询结果,以 errors 数组承载错误;错误项可给出消息与查询文档位置。诊断时应读取错误位置和消息,而非只看 HTTP 请求是否完成;部分执行场景还可能同时出现数据与错误。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 9 章《Consuming GraphQL APIs》(源文件:_epub-src/OEBPS/Text/09.htm)
- 结论依据:原文示例实际使用 errors 数组,并解释 message 与 locations;正文中的单数 error 属于笔误,卡片按示例与规范写法纠正。
- 原始内容:Error responses include an error key pointing to a list of all the errors found by the server. Each error is an object with the following keys: message —Includes a human-readable description of the error locations —Specifies where in the query the error was found, including the line and column