javascript - 是否可以有一个包含特定键的各种输入值的 GraphQL 突变?
问题描述
我正在尝试从我的客户向我的服务器发送具有以下结构的内容...
{
pet: cat,
food: [
{
brand: "Meow Mix",
types: "dry"
},
{
brand: "Friskies",
types: {
type1: dry,
type2: wet,
},
},
]
}
您可以看到它types
可以是 astring
或object
. 假设更多品牌将添加到包含 astring
或object
for的数组中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
}
解决方案
推荐阅读
- angular - Angular 升级后的构建错误 - MediaQueryListEvent 不可分配类型为 MediaQueryList
- javascript - 如何循环遍历地图
- c++11 - 有没有办法从另一个函数访问 main 中的变量?
- ios - 用户位置 MKAnnotationView 在 iOS 10、11、12 中相对于其他注解的显示顺序
- jmeter - 如何将 __evalVar 函数值保存到变量中并重新使用它进行比较
- r - 数据表输出的错误代码:参数不可解释为逻辑
- sql - SQL 查找至少放映过 2 次的电影
- android - 如何将 1800 秒格式化为 MM:SS 格式
- apache-spark - pyspark to_timestamp 函数不会转换某些时间戳
- php - 如何将重力表单条目数据发送到 aspx 第三方 url