-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolvers.js
46 lines (44 loc) · 983 Bytes
/
resolvers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const Task = require("./models/Task");
const resolvers = {
Query: {
hello: () => "Hello world",
getAllTasks: async () => {
const tasks = await Task.find();
return tasks;
},
async getTask(_, { id }) {
return await Task.findById(id);
},
},
Mutation: {
async createTask(parent, { task }, context, info) {
const { title, description } = task;
const newTask = new Task({ title, description });
await newTask.save();
return newTask;
},
async deleteTask(_, { id }) {
await Task.findByIdAndDelete(id);
return "Task Deleted";
},
async updateTask(_, { id, task }) {
const { title, description } = task;
const newTask = await Task.findByIdAndUpdate(
id,
{
$set: {
title,
description,
},
},
{
new: true,
}
);
return newTask;
},
},
};
module.exports = {
resolvers,
};