-
Notifications
You must be signed in to change notification settings - Fork 0
/
apollo.js
38 lines (36 loc) · 1.4 KB
/
apollo.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
//Packages
const {ApolloServer} = require("apollo-server-express");
const Dataloader = require('dataloader');
//TypeDefs & Resolvers
const typeDefs = require("./TypeDefs/main");
const resolvers = require("./Resolvers/main");
//Midlewares
const {Token} = require("./Authorization/Token");
//Loaders
const loaders = require("./Loaders/main");
const apolloServer = new ApolloServer({
typeDefs,
resolvers,
context: async ({req}) => {
await Token(req);
return {
reqUserInfo: req.user,
loaders: {
category: new Dataloader(keys => loaders.categoryLoaders.batchCategory(keys)),
subCategory: new Dataloader(keys => loaders.subCategoryLoaders.batchSubCategory(keys)),
brand: new Dataloader(keys => loaders.brandLoaders.batchBrand(keys)),
color: new Dataloader(keys => loaders.colorLoaders.batchColor(keys)),
shipping: new Dataloader(keys => loaders.shippingLoaders.batchShipping(keys)),
user: new Dataloader(keys => loaders.userLoaders.batchUser(keys)),
product: new Dataloader(keys => loaders.productLoaders.batchProduct(keys)),
coupon: new Dataloader(keys => loaders.couponLoaders.batchCoupon(keys))
}
}
},
formatError: (error) => {
return {
message: error.message
}
}
});
module.exports = apolloServer;