Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kenzotakahashi
Created August 2, 2018 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenzotakahashi/7711f755aa832589917326c9cba7cceb to your computer and use it in GitHub Desktop.
Save kenzotakahashi/7711f755aa832589917326c9cba7cceb to your computer and use it in GitHub Desktop.
const { GraphQLServer } = require('graphql-yoga')
const mongoose = require('mongoose')
require('dotenv').config()
const resolvers = require('./resolvers')
mongoose.connect(process.env.MONGODB_URI)
const db = mongoose.connection
db.on("error", console.error.bind(console, "connection error"))
db.once("open", function(callback){
console.log("Connection Succeeded")
})
const server = new GraphQLServer({
typeDefs: 'src/schema.graphql',
resolvers,
context: req => req,
})
const options = {
port: process.env.PORT || 5500,
endpoint: '/graphql',
subscriptions: '/subscriptions',
playground: '/playground',
}
server.start(options, ({ port }) => console.log(`Server is running on port ${port}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment