Created
September 14, 2016 19:34
-
-
Save helfer/24478065c542cb567d7965b414c1427a 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
import express from 'express'; | |
import Schema from './data/schema'; | |
import Resolvers from './data/resolvers'; | |
// import Mocks from './data/mocks'; | |
import { apolloExpress, graphiqlExpress } from 'apollo-server'; | |
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools'; | |
import bodyParser from 'body-parser'; | |
const GRAPHQL_PORT = 8080; | |
const graphQLServer = express(); | |
const executableSchema = makeExecutableSchema({ | |
typeDefs: Schema, | |
resolvers: Resolvers, | |
allowUndefinedInResolve: false, | |
printErrors: true, | |
}); | |
// addMockFunctionsToSchema({ | |
// schema: executableSchema, | |
// mocks: Mocks, | |
// preserveResolvers: true, | |
// }); | |
// `context` must be an object and can't be undefined when using connectors | |
graphQLServer.use('/graphql', bodyParser.json(), apolloExpress({ | |
schema: executableSchema, | |
context: {}, | |
})); | |
graphQLServer.use('/graphiql', graphiqlExpress({ | |
endpointURL: '/graphql', | |
})); | |
graphQLServer.listen(GRAPHQL_PORT, () => console.log( | |
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql` | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment