-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (48 loc) · 1.32 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const express = require('express');
const bodyParser = require('body-parser');
const {graphqlExpress, graphiqlExpress} = require('apollo-server-express');
const {makeExecutableSchema} = require('graphql-tools');
const helmet = require('helmet');
const morgan = require('morgan');
const cors = require('cors');
const personsDb = require('./database/person-database');
const timersDb = require('./database/timer-database');
import {Schema} from './schema/index';
const options = {
env: 'dev',
port: parseInt(process.env.PORT || '3000'),
routes: {
graphql: '/graphql',
graphiql: '/graphiql'
}
};
export function main() {
const app = express();
app.use(helmet());
app.use(morgan(options.env));
app.use(
options.routes.graphql,
cors()
);
app.use(
options.routes.graphql,
bodyParser.json(),
graphqlExpress({
context: {
...personsDb,
...timersDb,
},
schema: Schema
})
);
app.use(
options.routes.graphiql,
graphiqlExpress({endpointURL: options.routes.graphql})
);
app.listen(options.port,
() => {
console.log(`Go to http://localhost:${options.port}${options.routes.graphiql} to run queries!`);
}
);
}
main();