-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolvers.js
More file actions
67 lines (67 loc) · 1.79 KB
/
resolvers.js
File metadata and controls
67 lines (67 loc) · 1.79 KB
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
import db from './_db.js';
export const resolvers = {
Query: {
games() {
return db.games
},
game(_, args) {
return db.games.find((game) => game.id === args.id)
},
authors() {
return db.authors
},
author(_, args) {
return db.authors.find((author) => author.id === args.id)
},
reviews() {
return db.reviews
},
review(_, args) {
return db.reviews.find((review) => review.id === args.id)
},
},
Game: {
reviews(game) {
return db.reviews.filter((review) => review.game_id === game.id)
},
},
Author: {
reviews(author) {
return db.reviews.filter((review) => review.author_id === author.id)
},
},
Review: {
game(review) {
return db.games.find((game) => game.id === review.game_id)
},
author(review) {
return db.authors.find((author) => author.id === review.author_id)
},
},
Mutation: {
deleteGame(_, args) {
db.games = db.games.filter((game) => game.id !== args.id)
return db.games
},
addGame(_, args) {
let newGame = {
...args.game,
id: String(db.games.length + 1)
}
db.games.push(newGame)
return newGame
},
updateGame(_, args) {
db.games = db.games.map((game) => {
if (game.id === args.id) {
return {
...game,
...args.edits
}
}
return game
})
return db.games.find((game) => game.id === args.id)
},
}
}