Created
May 19, 2018 23:19
-
-
Save dupski/794cf86197249af86653f7f3092b48ac to your computer and use it in GitHub Desktop.
Create a GraphQL API in 5 minutes - routes
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 * 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