-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
34 lines (30 loc) · 977 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
const { ApolloServer } = require("apollo-server");
const schema = require("./schema");
const schema2 = require("./schema2");
const makeSchema = require("./makeSchema");
const data = require("./data2");
const JsonPlaceholderResource = require("./JsonPlaceholderResource");
const PostModel = require("./PostModel");
const UserModel = require("./UserModel");
const jsonPlaceholderResource = new JsonPlaceholderResource(
"https://jsonplaceholder.typicode.com"
);
async function makeServer() {
const schema = await makeSchema();
return new ApolloServer({
schema: schema,
context: ({ req }) => {
const userId = req.headers["authentication"];
return {
postModel: new PostModel(jsonPlaceholderResource, userId),
userModel: new UserModel(jsonPlaceholderResource, userId),
userId: userId
};
}
});
}
makeServer().then(server =>
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
})
);