返回主题:GraphQL 模式、查询与执行

知识卡片

普通读书笔记卡 · 3509.e

联合类型需判定具体成员

理解等级:中级

解析器返回联合类型或接口的结果时,服务器需要知道每个对象实际属于哪种具体类型,才能验证字段并应用客户端片段。类型解析器可依据可靠的判别信息返回模式中的类型名;未知形状应显式处理,避免误判为某个默认类型。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《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.