Skip to content

Instantly share code, notes, and snippets.

@dupski
Created May 19, 2018 23:19
Show Gist options
  • Save dupski/794cf86197249af86653f7f3092b48ac to your computer and use it in GitHub Desktop.
Save dupski/794cf86197249af86653f7f3092b48ac to your computer and use it in GitHub Desktop.
Create a GraphQL API in 5 minutes - routes
import * as Koa from 'koa';
import * as KoaRouter from 'koa-router';
import { api } from './models';
import { graphqlKoa, graphiqlKoa } from 'apollo-server-koa';
export function registerRoutes(app: Koa) {
const router = new KoaRouter();
const schema = api.getGraphQLSchema();
router.post('/graphql', graphqlKoa({ schema: schema }));
router.get('/graphql', graphqlKoa({ schema: schema }));
router.get('/graphiql', graphiqlKoa({ endpointURL: '/graphql' }));
app.use(router.routes());
app.use(router.allowedMethods());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment