Skip to content

Instantly share code, notes, and snippets.

@wojciech-bilicki
Created April 11, 2018 13:07
Show Gist options
  • Save wojciech-bilicki/6b50f2900be0f0b10b3fb725f07e349c to your computer and use it in GitHub Desktop.
Save wojciech-bilicki/6b50f2900be0f0b10b3fb725f07e349c to your computer and use it in GitHub Desktop.
Adding connection to the DB
import express from 'express';
import {graphiqlExpress, graphqlExpress } from 'apollo-server-express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import schema from './schema';
const server = express();
server.use('/graphiql', graphiqlExpress({
endpointURL: "/graphql"
}))
mongoose.connect('mongodb://localhost/graphqlTutorial')
const connection = mongoose.connection;
connection.once('open', () => {
console.log('====================================')
console.log('Connection to DB open!')
console.log('====================================')
})
server.use('/graphql',bodyParser.json(), graphqlExpress({
schema
}))
server.listen(4000, () => {
console.log('Server ready on port 4000')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment