Skip to content

Commit

Permalink
add resolver to remove todo
Browse files Browse the repository at this point in the history
  • Loading branch information
onprem committed Jun 10, 2019
1 parent 481d076 commit 21749ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ const resolvers = {
message: 'successfully toggled ToDo',
todo: toDo
}
},
removeTodo: async ( _, args, context ) => {
await context.db.collection('users').updateOne(
{ _id: ObjectId(context.id) },
{ $pull: { todos: { id: args.todoId } } }
);

return {
code: '200',
success: true,
message: 'successfully removed ToDo'
}
}
},
MutationResponse: {
Expand Down
2 changes: 2 additions & 0 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const typeDefs = gql`
toggleTodo( todoId: ID! ): TodoResponse!
removeTodo( todoId: ID! ): TodoResponse!
login( email: String!, password: String! ): String # login token
signup( name: String!, email: String!, password: String! ): User
Expand Down

0 comments on commit 21749ed

Please sign in to comment.