-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathresolvers.js
More file actions
38 lines (38 loc) · 990 Bytes
/
resolvers.js
File metadata and controls
38 lines (38 loc) · 990 Bytes
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
export default {
Author: {
posts: (parent, args, context, info) => parent.getPosts(),
},
Post: {
author: (parent, args, context, info) => parent.getAuthor(),
},
Query: {
posts: (parent, args, { db }, info) => db.post.findAll(),
authors: (parent, args, { db }, info) => db.author.findAll(),
post: (parent, { id }, { db }, info) => db.post.findById(id),
author: (parent, { id }, { db }, info) => db.author.findById(id)
},
Mutation: {
createPost: (parent, { title, content, authorId }, { db }, info) =>
db.post.create({
title: title,
content: content,
authorId: authorId
}),
updatePost: (parent, { title, content, id }, { db }, info) =>
db.post.update({
title: title,
content: content
},
{
where: {
id: id
}
}),
deletePost: (parent, {id}, { db }, info) =>
db.post.destroy({
where: {
id: id
}
})
}
};