【问题标题】:defining a GraphQL mutation in DGraph that adds a node that is of union type within another node在 DGraph 中定义一个 GraphQL 突变,在另一个节点中添加一个联合类型的节点
【发布时间】:2021-05-04 17:55:07
【问题描述】:

我是 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
    }
    } 
    }

【问题讨论】:

    标签: graphql dgraph


    【解决方案1】:

    在另一个页面上找到了答案: 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
            }
          }
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-02
      • 2018-05-13
      • 2019-12-07
      • 2016-04-03
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多