Created
August 2, 2018 01:22
-
-
Save kenzotakahashi/7711f755aa832589917326c9cba7cceb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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