graphql - 在 DGraph 中定义一个 GraphQL 突变,在另一个节点中添加一个联合类型的节点
问题描述
我是 GraphQL 和 Dgraph 的新手,并且一直在阅读手册。
我正在关注此处发布的手册中的示例: https ://dgraph.io/docs/graphql/schema/types/#union-type
我正在寻求使用突变来添加节点或节点列表,并将它们关联为 addHome 输入函数中可接受的成员。
然而,这些节点也是 Union 类型,因此我需要以某种方式将 HomeMember 转换为 Dog 并将类别定义为动物。
我看到有人在这里发布了一些东西,但我无法将这些部分拼凑在一起,因为它建议的代码似乎已经由 DGraph 生成: https ://discuss.dgraph.io/t/union-types-in-graphql/9581
我不确定,但有一种感觉,我可能需要以某种方式覆盖由 DGraph 自动生成到模式中的输入 HomeMemberRef 并禁用鹦鹉和人类?
到目前为止,我的代码如下所示:
mutation {
addHome(input: [
{address: "London",
// Here I need to add something a member that casts the
// HomeMember to a Dog, defines the category as an animal and is accepted within
// this addHome input function
}
]) {
home{
address
id
members
}
}
}
解决方案
在另一个页面上找到了答案: https ://dgraph.io/docs/graphql/mutations/mutations-overview/
我的 GraphQL 使用这个:
mutation {
addHome(input: [
{address: "London",
members: [
{ dogRef: { category: Mammal, breed: "German Shepherd"} },
]
}
]) {
home {
address
members {
... on Dog {
breed
}
... on Parrot {
repeatsWords
}
... on Human {
name
}
}
}
}
}
推荐阅读
- azure-devops - 为什么构建触发器抱怨 Webhooks 丢失
- sql - SQL中exists和not exists的用法
- python-3.x - what is difference in get() and get_nowait() in stack?
- python - Should an embedded SQLite DB used by CLI app be uploaded to version-control (Git)?
- python - Download file from VM 'pyvmomi'
- inheritance - UI5 extension of controller and lifecycle methods
- python - How to handle and do multiple requests for Multiple page response JSON
- css - Pseudo-class inheritance understanding
- python - How to delete a message when clicking on another button in Telebot?
- html - 无法将纯 HTML 类应用于 Blazor 组件