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

知识卡片

普通读书笔记卡 · 3503.h

接口与联合表达不同复用

理解等级:高级

GraphQL 接口规定多个对象类型必须共同提供的字段,适合需要统一查询共同属性时使用;联合类型把不同对象类型列为一种可能返回的集合,并不声明共同字段。蛋糕和饮料可实现相同产品接口,同时组成 Product 联合,以不同方式服务类型复用与多态查询。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 8 章《Designing GraphQL APIs》(源文件:_epub-src/OEBPS/Text/08.htm) - 结论依据:原文分别定义接口共享属性、联合容纳多个类型,并以 Cake/Beverage 实现 ProductInterface、构成 Product union 演示两种角色。 - 原始内容:Interfaces are useful when we have types that share properties in common. ... A union type is the combination of different types using the pipe ( | ) operator.