大家好,我陷入了一个内部带有数组的变异中,一次只能变异多个对象。
这是我的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~"
}
]
)
}