I am new to graphql and tried to add a unique schema in graphql but got such error.
This is the schema:
const mongoose = require('mongoose');
const { Schema } = mongoose;
const incidentSchema = new Schema({
incidentNumber: {type: String, required: true, unique: true},
releaseDate: {type: String, required: true}
});
module.exports = mongoose.model('Incident', incidentSchema);
In graphql mutation:
addIncident: {
type: IncidentType,
args: {
incidentNumber: { type: GraphQLString },
releaseDate: { type: GraphQLString }
},
resolve(parent, args) {
let incident = new Incident({
incidentNumber: args.incidentNumber,
releaseDate: args.releaseDate
});
return incident.save();
}
}
Do not know what needs to be done for this issue