知识卡片
联合类型需判定具体成员
解析器返回联合类型或接口的结果时,服务器需要知道每个对象实际属于哪种具体类型,才能验证字段并应用客户端片段。类型解析器可依据可靠的判别信息返回模式中的类型名;未知形状应显式处理,避免误判为某个默认类型。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 10 章《Building GraphQL APIs with Python》(源文件:_epub-src/OEBPS/Text/10.htm)
- 结论依据:原文用 Product 联合 Cake 与 Beverage 说明单纯返回对象列表仍无法确定成员类型,需额外类型解析器。
- 原始内容:A type resolver is a function that determines the type of an object. This example shows how the resolve_product_type() resolver determines the type of an object returned by the resolve_all_products() resolver.