Hello guys I got stuck in a mutation with array inside it to mutate multiple objects at a time.
So here is my Schema of my InstalmentsGroup
import mongoose from "mongoose";
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);
These are my types
type Instalment {
_id: ID!
instalmentCount: Int!
instalmentAmout: Int!
dueTo: Date!
instalmentGroup: InstalmentGroup
}
type InstalmentGroup {
_id: ID!
offer: ID!
instalments: [Instalment!]!
}
And this is my mutation
createInstalmentGroup(
offer: ID!
instalments: [Instalment!]!
): InstalmentGroup
And 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!]!.`
What I want to do is something to look like this
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~"
}
]
)
}