-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolvers.js
69 lines (63 loc) · 1.92 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import Sequelize from "sequelize";
const Op = Sequelize.Op;
export default {
User: {
posts: ({ id }, args, { models }) =>
models.Post.findAll({
where: { creatorPostId: id }
}),
comments: ({ id }, args, { models }) =>
models.Comment.findAll({
where: { creatorCommentId: id }
})
},
Post: {
comments: ({ id }, args, { models }) =>
models.Comment.findAll({
where: { postId: id }
})
},
Comment: {
creatorComment: ({ creatorCommentId }, args, { models }) =>
models.User.findOne({
where: { id: creatorCommentId }
})
},
Query: {
allUser: (parent, args, { models }) => models.User.findAll(),
getUser: (parent, { input: { id } }, { models }) =>
models.User.findOne({
where: { id }
}),
searchUsername: (parent, { username }, { models }) =>
models.User.findAll({
where: { username: { [Op.substring]: username } }
// ,order: [["username", "DESC"]]
}),
getUserPost: (parent, { creatorPostId }, { models }) => {
models.Post.findAll({
where: { creatorPostId }
});
},
getUserComment: (parent, { creatorCommentId }, { models }) => {
models.Comment.findAll({
where: { creatorCommentId }
});
}
},
Mutation: {
createUser: (parent, { input: { username, email } }, { models }) =>
models.User.create({ username, email }),
updateUser: (parent, { input: { id, email } }, { models }) =>
models.User.update({ email }, { where: { id } }),
deleteUser: (parent, { input: { id } }, { models }) =>
models.User.destroy({ where: { id } }),
createUserPost: (parent, { creatorPostId, post }, { models }) =>
models.Post.create({ creatorPostId, post }),
createUserComment: (
parent,
{ creatorCommentId, postId, comment },
{ models }
) => models.Comment.create({ creatorCommentId, postId, comment })
}
};