Created
June 29, 2018 08:07
-
-
Save nzaghini/ce54e0a77eeb6cdfce0963b3c7599767 to your computer and use it in GitHub Desktop.
Apollo Express setup for GraphQL with Context.
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 './src/schema' | |
import movieService from './src/dataSource/movieService' | |
const GRAPHQL_PORT = 3000 | |
const graphQLServer = express() | |
// by setting the context here, the Service is now available for Resolvers as context.movieService | |
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema, context: { movieService } })) | |
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