-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.ts
41 lines (36 loc) · 1.22 KB
/
server.ts
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
import {ApolloServer} from 'apollo-server-lambda'
import schema from './graphql/schema/schema'
import {AbstractLogger} from './core/logger/AbstractLogger'
import {AbstractSetting} from './core/config/AbstractSetting'
import {IAppContext} from './interfaces/IAppContext'
import {Injectable, Injector} from 'injection-js'
import {getContext} from './context'
@Injectable()
export class Server {
private apolloServer: ApolloServer
private graphqlPort: number
private context: IAppContext
constructor(private logger: AbstractLogger, private setting: AbstractSetting) {}
public initContext(injector: Injector) {
this.context = getContext(injector)
}
public initServer(injector: Injector) {
this.initContext(injector)
this.logger.info('Starting graphql server...')
this.graphqlPort = parseInt(this.setting.config.server.port, 10)
this.createApolloServer()
}
public getApolloInstance(): ApolloServer {
return this.apolloServer
}
private createApolloServer() {
const graphqlRoutePrefix = process.env.IS_OFFLINE ? '' : '/dev'
this.apolloServer = new ApolloServer({
schema,
context: this.context,
playground: {
endpoint: graphqlRoutePrefix + '/graphql'
}
})
}
}