【发布时间】:2020-08-25 16:25:24
【问题描述】:
在我的 mongodb 模型中,名称是必需的,但我想在 graphql 中将其设为可选。我该怎么做?
updateExercise: {
type: ExerciseType,
args: {
id: {type: new GraphQLNonNull(GraphQLString)},
username: {type: new GraphQLString},
description: {type: new GraphQLString},
duration: {type: new GraphQLInt},
date: {type: new GraphQLString}
},
resolve(parent, args) {
Exercise.findByIdAndUpdate(args.id)
.then(exercise => {
exercise.username = args.username,
exercise.description = args.description,
exercise.duration = args.duration,
exercise.date = args.date
exercise.save()
.then( () => 'Succesfully Updated')
.catch( e => console.log(e) )
})
}
}
【问题讨论】:
标签: graphql graphql-js