-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
57 lines (49 loc) · 1.05 KB
/
index.ts
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
import lodash from "lodash";
import { ApolloServer, gql, makeExecutableSchema } from "apollo-server";
import { Resolvers } from "./generated/types";
import * as DAL from "./data-access";
const commonTypeDefs = gql`
enum Category {
LEISURE
GAMING
FOOD
EXERCISE
OUTDOORS
}
type Review {
id: ID!
name: String!
rating: Int!
text: String
}
type Product {
id: ID!
name: String!
description: String!
categories: [Category!]!
reviews: [Review!]
}
type Query {
product(id: ID!): Product
products: [Product!]!
}
`;
const commonResolvers: Resolvers = {
Product: {
reviews: (root) => DAL.getReviewsForProduct(root.id),
},
Query: {
product: (_root, args) => DAL.getProductById(args.id),
products: () => DAL.getProducts(),
},
};
const schema = makeExecutableSchema({
typeDefs: [commonTypeDefs],
resolvers: lodash.merge(commonResolvers),
});
const server = new ApolloServer({
schema,
});
server.listen(3000).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});