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:
- TracePlugin -- provides Apollo Tracing support
- CachePlugin -- a full response cache
- LoggerPlugin -- base level logging plugin
- AuthPlugin -- schema defined authorization levels
- LocalizationPlugin -- query level localization directive
You can turn on the included GraphQL playground by setting the playgroundEndpoint
in the startup options.
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());
});