首页 > 解决方案 > 是否可以有一个包含特定键的各种输入值的 GraphQL 突变?

问题描述

我正在尝试从我的客户向我的服务器发送具有以下结构的内容...

{
  pet: cat,
  food: [
    {
      brand: "Meow Mix",
      types: "dry"
    },
    {
      brand: "Friskies",
      types: {
         type1: dry,
         type2: wet,
      }, 
    },
    
  ]
}

您可以看到它types可以是 astringobject. 假设更多品牌将添加到包含 astringobjectfor的数组中types。甚至可以通过 GraphQL 发送这种结构吗?如果是这样,该类型将如何构造?理想情况下,在这里使用 a 会很棒,union但这不适用于突变。

input Pets {
  pet: String!,
  food: [Brands!]!
}

input Brands {
  brand: String!,
  types: String! | FoodOptions  // here is where I'm getting stuck. i know `or` isn't possible but don't know of a different solution.
}

input FoodOptions {
  type1: String!,
  type2: String
}

标签: javascriptgraphqlapollo

解决方案


推荐阅读