Created
April 11, 2018 13:07
-
-
Save wojciech-bilicki/6b50f2900be0f0b10b3fb725f07e349c to your computer and use it in GitHub Desktop.
Adding connection to the DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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