-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (32 loc) · 859 Bytes
/
server.js
File metadata and controls
39 lines (32 loc) · 859 Bytes
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
const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { schema, resolver } = require('./schema');
const envs = require('./envs');
const { db } = require('./db');
const app = express();
app.use(express.json());
db.once('open', () => {
console.log('Connected to MongoDB');
});
db.on('error', (err) => {
console.log('Error connecting to MongoDB', err);
process.exit(1);
});
app.use(
envs.graphqlPath,
graphqlHTTP((request, response, graphQLParams) => ({
schema,
rootValue: resolver,
graphiql: true,
context: {
request,
response,
},
}))
);
app.get('/', (req, res, nex) => {
res.send("Hello World")
})
app.listen(envs.port, () => {
console.log(`Server is running at http://localhost:${envs.port}${envs.graphqlPath}`);
});