【发布时间】:2019-11-19 03:24:58
【问题描述】:
我得到了以下架构:
type Vehicle {
id: ID!
name: String!
color: String!
}
input AddVehicle {
name: String!
color: String!
}
input UpdateVehicle {
id: ID!
name: String!
}
现在我想为我的车辆添加一些属性,具体取决于车辆型号,例如
type CarProperties {
wheelSize: Int!
doors: Int!
}
type BoatProperties {
length: Int!
}
union VehicleProperties = CarProperties | BoatProperties
type Vehicle {
[ ... ]
properties: vehicleProperties!
}
所以编写查询非常简单,但是在进行突变时我很挣扎......
AFAIK graphQL 输入没有实现联合或接口(这里有一个相关线程https://github.com/graphql/graphql-spec/issues/488)
所以我在这里看到的解决方法是复制我的输入,例如:
input addBoatVehicle {
name: String!
color: String!
properties: BoatProperties!
}
等等updateBoatVehicle、addCarVehicle、updateCarVehicle。
但是如果我得到很多车型,或者可能是第三或第四个突变,恐怕很快就会变得很麻烦。
有什么推荐的方法来管理这个案例吗?
【问题讨论】:
标签: graphql