-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (38 loc) · 887 Bytes
/
server.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
require('dotenv').config();
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const typeDefs = gql`
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
class ServerClass{
constructor(){
this.app = express();
this.server = new ApolloServer({ typeDefs, resolvers });
this.port = process.env.PORT;
}
init(){
this.config();
}
async config(){
const app = this.app;
await this.server.start();
this.server.applyMiddleware({ app });
this.launch();
}
launch(){
const port = this.port;
console.log(this.port)
this.app.listen({ port }, () =>
console.log(`🚀 Server ready at http://localhost:${port}${this.server.graphqlPath}`)
);
}
}
const MyServer = new ServerClass();
MyServer.init();