Skip to content

Instantly share code, notes, and snippets.

@govorov
Created October 14, 2017 00:24
Show Gist options
  • Save govorov/37fb48ce70f4938b1c523bc1d7afecdc to your computer and use it in GitHub Desktop.
Save govorov/37fb48ce70f4938b1c523bc1d7afecdc to your computer and use it in GitHub Desktop.
import * as Router from 'koa-router';
import * as koaBody from 'koa-bodyparser';
import {
graphqlKoa,
graphiqlKoa,
} from 'apollo-server-koa';
import { schema } from 'graphql/schema';
export const routes = new Router();
// API entrypoint
const apiEntrypointPath = '/graphql';
const graphQlOpts = graphqlKoa({
schema,
});
routes.get(apiEntrypointPath, graphQlOpts);
routes.post(apiEntrypointPath, koaBody(), graphQlOpts);
// GraphiQL entrypoint
routes.get('/graphiql', graphiqlKoa({ endpointURL: apiEntrypointPath }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment