Skip to content

Instantly share code, notes, and snippets.

@Bensigo
Last active October 3, 2017 11:13
Show Gist options
  • Save Bensigo/3d679ab6784341b6af9fafddfd51810d to your computer and use it in GitHub Desktop.
Save Bensigo/3d679ab6784341b6af9fafddfd51810d to your computer and use it in GitHub Desktop.
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const cors = require('cors')
const {graphiqlExpress, graphqlExpress} = require('apollo-server-express')
const morgan = require('morgan')
// require app modules
const config = require('./config/config')
const schema = require('./graphql')
// making instance of app
const app = express()
// setting up middlewares
app.use(cors()) // TODO: add origin for the fontend
app.use(morgan('dev'))
// setup graphiql and graphql server
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql'
}))
app.use('/graphql', bodyParser.json(), graphqlExpress(req => ({
schema
})))
// connect to DB
mongoose.connect(config.DBURI, () => {
console.log('connected to DB successfully')
})
// start app server
app.listen(config.PORT, () => {
console.log('starting up graphql server')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment