Last active
November 5, 2017 09:52
-
-
Save abhitheawesomecoder/5b89441e9f5db6696af0dc602f31b56f to your computer and use it in GitHub Desktop.
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 { graphqlExpress, graphiqlExpress } from 'apollo-server-express'; | |
import bodyParser from 'body-parser'; | |
import schema from './data/schema'; | |
import cors from 'cors'; | |
import jwt from 'express-jwt'; | |
import Constants from './constants'; | |
import { User } from './data/connectors'; | |
const GRAPHQL_PORT = 4000; | |
const graphQLServer = express(); | |
graphQLServer.use('*', cors({ origin: 'http://192.168.1.3:8081' })); | |
graphQLServer.use('/graphql', bodyParser.json(), jwt({ | |
secret: Constants.SECRET, | |
credentialsRequired: false, | |
}), graphqlExpress(req => ({ | |
schema, | |
context: { | |
user: req.user ? User.findOne({ where: { id: req.user.id } }) : Promise.resolve(null), | |
}, | |
}))); | |
graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' })); | |
graphQLServer.listen(GRAPHQL_PORT, () => console.log( | |
`GraphiQL is now running on http://localhost:${GRAPHQL_PORT}/graphiql` | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment