今天,我在解决功能(GraphQL)内的db(drop)操作中遇到问题。代码在下面。
dropAuthor: {
type: authorType,
args: {id: idType},
async resolve(parent, args){
Book.deleteMany({authorId: args.id}).find();
return Author.deleteOne({_id: args.id});
}
}
GraphiQL查询在下面
mutation{
dropAuthor(id:"5bed7c23bff55c1086a7b4d4"){
id
}
}
每当我尝试删除“作者”表单集合时,它仅删除“作者”,并且保留已删除的书芯。这段代码有什么问题?
答案 0 :(得分:1)
dropAuthor: {
type: authorType,
args: { id: idType },
async resolve(parent, args){
let deleteBooks = Book.deleteMany({ authorId: args.id }).find();
let deleteAuthor = Author.deleteOne({ _id: args.id });
return Promise.all([deleteBooks, deleteAuthor]);
}
}
尝试此代码。