-
Notifications
You must be signed in to change notification settings - Fork 147
/
library-backend.js
121 lines (113 loc) · 3 KB
/
library-backend.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const { ApolloServer } = require('@apollo/server')
const { startStandaloneServer } = require('@apollo/server/standalone')
let authors = [
{
name: 'Robert Martin',
id: "afa51ab0-344d-11e9-a414-719c6709cf3e",
born: 1952,
},
{
name: 'Martin Fowler',
id: "afa5b6f0-344d-11e9-a414-719c6709cf3e",
born: 1963
},
{
name: 'Fyodor Dostoevsky',
id: "afa5b6f1-344d-11e9-a414-719c6709cf3e",
born: 1821
},
{
name: 'Joshua Kerievsky', // birthyear not known
id: "afa5b6f2-344d-11e9-a414-719c6709cf3e",
},
{
name: 'Sandi Metz', // birthyear not known
id: "afa5b6f3-344d-11e9-a414-719c6709cf3e",
},
]
/*
* Suomi:
* Saattaisi olla järkevämpää assosioida kirja ja sen tekijä tallettamalla kirjan yhteyteen tekijän nimen sijaan tekijän id
* Yksinkertaisuuden vuoksi tallennamme kuitenkin kirjan yhteyteen tekijän nimen
*
* English:
* It might make more sense to associate a book with its author by storing the author's id in the context of the book instead of the author's name
* However, for simplicity, we will store the author's name in connection with the book
*
* Spanish:
* Podría tener más sentido asociar un libro con su autor almacenando la id del autor en el contexto del libro en lugar del nombre del autor
* Sin embargo, por simplicidad, almacenaremos el nombre del autor en conexión con el libro
*/
let books = [
{
title: 'Clean Code',
published: 2008,
author: 'Robert Martin',
id: "afa5b6f4-344d-11e9-a414-719c6709cf3e",
genres: ['refactoring']
},
{
title: 'Agile software development',
published: 2002,
author: 'Robert Martin',
id: "afa5b6f5-344d-11e9-a414-719c6709cf3e",
genres: ['agile', 'patterns', 'design']
},
{
title: 'Refactoring, edition 2',
published: 2018,
author: 'Martin Fowler',
id: "afa5de00-344d-11e9-a414-719c6709cf3e",
genres: ['refactoring']
},
{
title: 'Refactoring to patterns',
published: 2008,
author: 'Joshua Kerievsky',
id: "afa5de01-344d-11e9-a414-719c6709cf3e",
genres: ['refactoring', 'patterns']
},
{
title: 'Practical Object-Oriented Design, An Agile Primer Using Ruby',
published: 2012,
author: 'Sandi Metz',
id: "afa5de02-344d-11e9-a414-719c6709cf3e",
genres: ['refactoring', 'design']
},
{
title: 'Crime and punishment',
published: 1866,
author: 'Fyodor Dostoevsky',
id: "afa5de03-344d-11e9-a414-719c6709cf3e",
genres: ['classic', 'crime']
},
{
title: 'Demons',
published: 1872,
author: 'Fyodor Dostoevsky',
id: "afa5de04-344d-11e9-a414-719c6709cf3e",
genres: ['classic', 'revolution']
},
]
/*
you can remove the placeholder query once your first one has been implemented
*/
const typeDefs = `
type Query {
dummy: Int
}
`
const resolvers = {
Query: {
dummy: () => 0
}
}
const server = new ApolloServer({
typeDefs,
resolvers,
})
startStandaloneServer(server, {
listen: { port: 4000 },
}).then(({ url }) => {
console.log(`Server ready at ${url}`)
})