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

知识卡片

普通读书笔记卡 · 3505.a

内联片段按实际类型选字段

理解等级:中级

联合类型返回值可能落在不同对象类型上。内联片段用 ... on 类型 限定字段选择,让查询分别读取各具体类型的专属字段;若这些类型还实现同一接口,也可在接口片段中选共有字段。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 9 章《Consuming GraphQL APIs》(源文件:_epub-src/OEBPS/Text/09.htm) - 结论依据:原文先展示联合类型直接取 name 的错误,再用 ProductInterface、Cake、Beverage 的内联片段选择对应字段。 - 原始内容:An inline fragment is an anonymous selection set on a specific type. The syntax for inline fragments includes three dots (the spread operator in JavaScript) followed by the on keyword and the type on which the selection set applies