Skip to content

Instantly share code, notes, and snippets.

@helfer
Created September 14, 2016 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helfer/24478065c542cb567d7965b414c1427a to your computer and use it in GitHub Desktop.
Save helfer/24478065c542cb567d7965b414c1427a to your computer and use it in GitHub Desktop.
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