Mayur
Mayur

Reputation: 5053

how to pass two queries in resolve function GraphQL?

Today I face an issue in db(drop) operation inside resolve function(GraphQL). Code is below.

dropAuthor: {
type: authorType,
            args: {id: idType},
            async resolve(parent, args){
                Book.deleteMany({authorId: args.id}).find();
                return Author.deleteOne({_id: args.id});
            }
}

GraphiQL query is below

mutation{  
  dropAuthor(id:"5bed7c23bff55c1086a7b4d4"){
    id
  }
}

Whenever I try to delete Author form collection It deletes only Author, and recored of books are stay without delete. What is the problem in this code?

Upvotes: 1

Views: 54

Answers (1)

sohamdodia
sohamdodia

Reputation: 377

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]);
  }
}

Try this code.

Upvotes: 1

Related Questions