Skip to content

erkkah/tiny-graphql-koa

Repository files navigation

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());
});

About

Tiny GraphQL-serving middleware for Koa

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy