知识卡片
边字段连接对象类型
GraphQL 对象字段可指向另一对象类型,形成从当前类型出发的可查询关系;例如原料的 supplier 指向供应商。关系默认沿字段声明方向可遍历,若要反向遍历,需在另一类型上也声明相应字段。边是 API 查询结构,不等同于数据库自动建立外键。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 8 章《Designing GraphQL APIs》(源文件:_epub-src/OEBPS/Text/08.htm)
- 结论依据:原文以 Ingredient 的 supplier 字段连接 Supplier,并说明只从 Ingredient 可达 Supplier;反向关系需在 Supplier 中声明 ingredients 字段。
- 原始内容:Types can be connected by creating a property that points to another type. ... To make the connection between Supplier and the Ingredient bidirectional, 4 we need to add a property to the Supplier type that points to the Ingredient type.