-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
55 lines (49 loc) · 912 Bytes
/
index.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
const { ApolloServer, gql } = require('apollo-server');
const data = {
"beasts": [
{
"id": "md",
"legs": 6,
"binomial": "Musca domestica",
"commonName": "housefly",
},
{
"id": "nr",
"legs": 8,
"binomial": "Neriene radiata",
"commonName": "filmy dome spider",
},
{
"id": "cc",
"legs": 2,
"binomial": "Corvus corone",
"commonName": "carrion crow",
},
{
"id": "fc",
"legs": 4,
"binomial": "Felis catus",
"commonName": "cat",
}
]
};
const typeDefs = gql`
type Beast {
id: ID
legs: Int
binomial: String
commonName: String
}
type Query {
beasts: [Beast]
}
`;
const resolvers = {
Query: {
// Returns array of all beasts.
beasts: () => data.beasts
}
};
const server = new ApolloServer({ typeDefs, resolvers });
// The `listen` method launches a web server.
server.listen(4000);