-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
114 lines (104 loc) · 2.63 KB
/
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
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
const { ApolloServer, gql } = require("apollo-server");
const productController = require("./controller/productController");
const typeDefs = gql`
type product {
id: Int
title: String
T_number: Int
color: String
price: Int
size: String
amount: Int
category: String
imgURL: String
descripiton: String
}
type productList {
products: [product]
nextPage: Int
}
type Query {
productList(paging: Int, pageSize: Int, category: String): productList
product(T_number: Int): product
}
type createProduct {
product: product
insertID: Int
}
type updateProduct {
product: product
insertID: Int
}
input productInfo {
id: Int
title: String
T_number: Int
color: String
price: Int
size: String
amount: Int
category: String
imgURL: String
descripiton: String
}
type Mutation {
createProduct(input: productInfo): createProduct
updateProduct(input: productInfo, id: Int): updateProduct
}
`;
const resolvers = {
Query: {
productList(parent, args) {
return productController.productList(
args.paging,
args.pageSize,
args.category
);
},
product(parent, args) {
return productController.product(args.T_number);
},
},
Mutation: {
createProduct(parent, args) {
const productInfo = {
title: args.input.title,
T_number: args.input.T_number,
color: args.input.color,
size: args.input.size,
price: args.input.price,
amount: args.input.amount,
category: args.input.category,
descripiton: args.input.descripiton,
imgURL: args.input.imgURL,
};
const insertID = productController.createProduct(productInfo);
return { product: productInfo, insertID: insertID };
},
updateProduct(parent, args) {
const productInfo = {
title: args.input.title,
T_number: args.input.T_number,
color: args.input.color,
size: args.input.size,
price: args.input.price,
amount: args.input.amount,
category: args.input.category,
descripiton: args.input.descripiton,
imgURL: args.input.imgURL,
};
const insertID = productController.updateProduct(productInfo, args.id);
return { product: productInfo, insertID: insertID };
},
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
csrfPrevention: true,
});
server.listen().then(({ url }) => {
console.log(
`🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Server ready at ${url} 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀`
);
});