mongodb - 如何使用 GraphQL 制作包含对象数组的组突变?
问题描述
大家好,我陷入了一个突变,其中有一个数组,一次突变多个对象。
所以这是我的架构InstalmentsGroup
从“猫鼬”导入猫鼬;
const Schema = mongoose.Schema;
const InstalmentsGroupSchema = new Schema(
{
offer: {
type: Schema.Types.ObjectId,
ref: "Offer"
},
instalmentCount: { type: Number },
instalmentAmout: { type: Number },
dueTo: { type: Date }
},
{ timestamps: true }
);
export default mongoose.model("InstalmentsGroup", InstalmentsGroupSchema);
这些是我的types
type Instalment {
_id: ID!
instalmentCount: Int!
instalmentAmout: Int!
dueTo: Date!
instalmentGroup: InstalmentGroup
}
type InstalmentGroup {
_id: ID!
offer: ID!
instalments: [Instalment!]!
}
这是我的mutation
createInstalmentGroup(
offer: ID!
instalments: [Instalment!]!
): InstalmentGroup
和resolver
createInstalmentGroup: async (_, { ...args }, { user }) => {
try {
await requireAuth(user);
const instalments = await InstalmentsGroup.create({ ...args });
return instalments;
} catch (error) {
throw error;
}
}
Now all I got is this `Error: The type of Mutation.createInstalmentGroup(instalments:) must be Input Type but got: [Instalment!]!.`
我想做的是看起来像这样
mutation {
createInstalmentGroup(
offer: "5cc8876242b1ad68efdd7df3",
instalments: [
{
instalmentCount: 1,
instalmentAmout: 2000,
dueTo: "2019-06-01T23:00:00.000Z"
}. {
instalmentCount: 2,
instalmentAmout: 2000,
dueTo: "2019-07-01T23:00:00.000~"
}
]
)
}
解决方案
推荐阅读
- reactjs - 如何在网络浏览器上隐藏反应源代码?
- swift - 子类化 UIButton 标题字体大小意外更改
- kubernetes - 如何在我的 Kubernetes 容器中安装 tar 二进制文件以使 kubectl cp 工作?
- c# - ContentControl 中的 WinUI 3 DataTemplateSelector 不起作用
- load - 局域网下如何实现双机热备和负载均衡
- amazon-web-services - 第三方 WAF(和 SSL 卸载)背后的 AWS ALB
- linux - 在 Visual Studio Code 中为目录命名
- flutter - 更改参数时,任何 Animatedx 小部件都不会进行插值(Flutter/Dart)
- r - makeCluster 在 Windows 上挂起 - 并行包
- php - 如何从包含父项和子项的单个表数据创建数组?