-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (49 loc) · 1.54 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
import {importSchema} from "graphql-import";
import {Query} from "./resolvers/Query.js";
import {setLang} from "./resolvers/Query.js";
import Mutation from "./resolvers/Mutation.js";
import Subscription from "./resolvers/Subscription.js";
import {ApolloServer} from "apollo-server-express";
import {createServer} from 'http';
import {makeExecutableSchema} from '@graphql-tools/schema';
import {SubscriptionServer} from "subscriptions-transport-ws"
import {execute, subscribe} from "graphql"
import app from "./app.js"
import {GraphQLUpload} from 'graphql-upload';
const PORT = process.env.NODEJS_PORT ?? 80;
const {schema, server} = setUpGraphqlServer();
function setUpGraphqlServer() {
const typeDefs = importSchema("./schema.graphql");
const schema = makeExecutableSchema({
typeDefs,
resolvers: {
Upload: GraphQLUpload,
Query,
Mutation,
Subscription,
},
});
const server = new ApolloServer({
typeDefs,
//todo pass context to resolver
resolvers: {
Query,
Mutation,
Subscription,
},
context: ({req}) => {
setLang(req.headers["content-language"])
},
});
return {schema, server};
}
const httpServer = createServer(app);
await server.start();
server.applyMiddleware({app});
SubscriptionServer.create(
{schema, execute, subscribe},
{server: httpServer, path: server.graphqlPath}
);
httpServer.listen(PORT, () => {
console.log(`🚀 server has been started on ${PORT}`,);
});