forked from benawad/graphql-express-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolvers.js
64 lines (63 loc) · 1.59 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
export default {
User: {
boards: ({ id }, args, { models }) =>
models.Board.findAll({
where: {
owner: id,
},
}),
suggestions: ({ id }, args, { models }) =>
models.Suggestion.findAll({
where: {
creatorId: id,
},
}),
},
Board: {
suggestions: ({ id }, args, { models }) =>
models.Suggestion.findAll({
where: {
boardId: id,
},
}),
},
Suggestion: {
creator: ({ creatorId }, args, { models }) =>
models.User.findOne({
where: {
id: creatorId,
},
}),
},
Query: {
allUsers: (parent, args, { models }) => models.User.findAll(),
getUser: (parent, { username }, { models }) =>
models.User.findOne({
where: {
username,
},
}),
userBoards: (parent, { owner }, { models }) =>
models.Board.findAll({
where: {
owner,
},
}),
userSuggestions: (parent, { creatorId }, { models }) =>
models.Suggestion.findAll({
where: {
creatorId,
},
}),
},
Mutation: {
createUser: (parent, args, { models }) => models.User.create(args),
updateUser: (parent, { username, newUsername }, { models }) =>
models.User.update({ username: newUsername }, { where: { username } }),
deleteUser: (parent, args, { models }) =>
models.User.destroy({ where: args }),
createBoard: (parent, args, { models }) => models.Board.create(args),
createSuggestion: (parent, args, { models }) =>
models.Suggestion.create(args),
},
};