-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·29 lines (25 loc) · 733 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
const http = require('http');
const express = require('express');
const graphqlHTTP = require('express-graphql');
const schema = require("./schema");
const db = require('./database/models');
const loaders = require('./schema/loader');
const app = express();
app.use('/graphql', graphqlHTTP({
schema: schema,
context: {
loaders: loaders
},
rootValue: {
db: db.models,
},
graphiql: process.env.NODE_ENV !== 'production',
pretty: process.env.NODE_ENV !== 'production',
}));
const port = 4000;
const server = http.createServer(app);
db.once('open', () => {
server.listen(port, () => {
console.log(`Running a GraphQL API server at http://localhost:${port}/graphql`);
});
});