forked from utkarshp21/graphql-server-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (21 loc) · 809 Bytes
/
app.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
const express = require('express');
const graphqlHTTP = require('express-graphql');
const schema = require('./schema/schema')
const app = express();
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/graphql')
mongoose.connection.once('open', () => {
console.log('conneted to database');
});
//This route will be used as an endpoint to interact with Graphql,
//All queries will go through this route.
app.use('/graphql', graphqlHTTP({
//Directing express-graphql to use this schema to map out the graph
schema,
//Directing express-graphql to use graphiql when goto '/graphql' address in the browser
//which provides an interface to make GraphQl queries
graphiql:true
}));
app.listen(3000, () => {
console.log('Listening on port 3000');
});