Making update request using graphql
Wrong arguments:
I'm used to Apollo, because of its simplified structure. In Apollo I've encountered a similar issue whereas the arguments of queries and mutations in the resolver consist of 4 different items.
updatePost: (parent,args,context,info) => { // <-- look at this line console.log(args); Post.findByIdAndUpdate(args._id, {$set: { title: args.postInput.title, description: args.postInput.description, content: args.postInput.content, date: new Date(args.postInput.date) }}).then(result => { console.log(result); return { ...result._doc } }).catch (err =>{ throw err; }); },ExampleMutation2: ...
Bonus ECMA:
I would also recommend to use the await/async version of the resolver method in order to get a response and not a Promise. Read https://www.greycampus.com/blog/programming/java-script-versions in order to make your code simpler using the latest ECMAScript
updatePost: async (parent,args,context,info) => { try{ console.log(args); let result= await Post.findByIdAndUpdate(args._id, {$set: { title: args.postInput.title, description: args.postInput.description, content: args.postInput.content, date: new Date(args.postInput.date) }}) console.log(result); return result._doc }catch (err =>{ throw err; }); }, ExampleMutation2: ...
I know that i am late an you probably fixed it but it might help someone else.
type RootMutation { updatePost(_id: ID!, postInput: PostInput!): Post
instead write:
updatePost(id: ID!, postInput: PostInput!): Post!