Last active
July 31, 2017 16:45
-
-
Save rgstephens/352ecbabab7d8964d661729aed200e25 to your computer and use it in GitHub Desktop.
Sample Apollo-Server w/Express
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
import express from 'express'; | |
import bodyParser from 'body-parser'; | |
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'; | |
import schema from './schema.js' | |
const PORT = 3000; | |
const app = express(); | |
console.log('calling app.js'); | |
// bodyParser is needed just for POST. | |
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: schema })); | |
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' })); | |
app.get('/', function (req, res) { | |
res.send('Hello World!') | |
}); | |
app.listen(PORT, () => console.log( | |
`GraphiQL is now running on http://localhost:${PORT}/graphiql` | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment