-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
43 lines (37 loc) · 716 Bytes
/
index.ts
File metadata and controls
43 lines (37 loc) · 716 Bytes
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
import { GraphQLServer } from "graphql-yoga";
const PORT = process.env.PORT || 80;
const typeDefs = `
type Query {
company(id: Int): Company
companies: [Company]
}
type Company {
id: Int
name: String
}
`;
const companies = {
1: {
id: 1,
name: "Super BV"
},
2: {
id: 2,
name: "Uber BV"
},
3: {
id: 3,
name: "Terra BV"
}
};
const resolvers = {
Query: {
company: (_, { id }) => companies[id],
companies: () => Object.keys(companies).map(key => companies[key])
}
};
const server = new GraphQLServer({ typeDefs, resolvers });
server.start({ port: PORT }, () =>
console.log(`Server is running on localhost:${PORT}`)
);
export default server;