im是graphql的新功能,对我的服务器使用express-graphql。我对突变部分有疑问,如果成功进行某些操作(更改密码),如何发送成功消息,这是我的更改密码的突变字段
changePassword: {
type: UserType,
args: {
id: { type: new GraphQLNonNull(GraphQLID) },
password: { type: new GraphQLNonNull(GraphQLString) },
newPassword: { type: new GraphQLNonNull(GraphQLString) },
},
resolve(parent, args) {
return User.findById({ _id: args.id })
.then(async resp => {
const checkPassword = await comparePassword(args.password, resp.password);
if (checkPassword) {
return resp;
} else {
throw new Error('WRONG_PASSWORD');
}
})
.then(async resp => {
const hashedPassword = await hashPassword(args.newPassword);
await User.updateOne({ _id: args.id }, { $set: { password: hashedPassword }});
return resp
})
.catch(err => {
console.log(err.message);
return err;
});
},
},
我在哪里或如何实现我的意图?