Skip to content

Instantly share code, notes, and snippets.

@rgstephens
Last active July 31, 2017 16:45
Show Gist options
  • Save rgstephens/352ecbabab7d8964d661729aed200e25 to your computer and use it in GitHub Desktop.
Save rgstephens/352ecbabab7d8964d661729aed200e25 to your computer and use it in GitHub Desktop.
Sample Apollo-Server w/Express
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