tiny-graphql-koa
TypeScript icon, indicating that this package has built-in type declarations

0.9.3 • Public • Published

tiny-graphql-koa

A tiny GraphQL-serving middleware for Koa, built on the great graphql-api-koa middleware.

Reduces the steps to get up and running, and provides plugin support to extend the GraphQL server functionality.

Included plugins:

You can turn on the included GraphQL playground by setting the playgroundEndpoint in the startup options.

Getting started

Install using npm:

$ npm add tiny-graphql-koa

Example using plugins and the playground:

import Koa from "koa";
import gql from "graphql-tag";

import { makeServerMiddleware, CachePlugin, TracePlugin } from "tiny-graphql-koa";

const app = new Koa();

const graphqlServer = makeServerMiddleware({
    typedefs: [
        gql`
            type Query {
                version: String! @cache(ttl: SHORT)
            }
        `,
    ],
    resolvers: [
        {
            Query: {
                version: () => "1.2.3"
            }
        }
    ],
    plugins: [new TracePlugin(), new CachePlugin()],
    playgroundEndpoint: "/playground",
});

app.use(graphqlServer);
const server = app.listen(3000).on("listening", () => {
    console.log("Up and running at:", server.address());
});

Package Sidebar

Install

npm i tiny-graphql-koa

Weekly Downloads

7

Version

0.9.3

License

ISC

Unpacked Size

85 kB

Total Files

33

Last publish

Collaborators

  • erkkah