Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erkkah/tiny-graphql-koa
Tiny GraphQL-serving middleware for Koa
https://github.com/erkkah/tiny-graphql-koa
graphql graphql-server koa koa-middleware
Last synced: about 1 month ago
JSON representation
Tiny GraphQL-serving middleware for Koa
- Host: GitHub
- URL: https://github.com/erkkah/tiny-graphql-koa
- Owner: erkkah
- License: isc
- Created: 2020-10-15T08:10:43.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-10T14:23:30.000Z (over 1 year ago)
- Last Synced: 2024-05-09T09:55:20.458Z (6 months ago)
- Topics: graphql, graphql-server, koa, koa-middleware
- Language: TypeScript
- Homepage:
- Size: 360 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-graphql-koa
A tiny GraphQL-serving middleware for Koa, built on the great [graphql-api-koa](https://github.com/jaydenseric/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](./src/TracePlugin.ts) -- provides [Apollo Tracing](https://github.com/apollographql/apollo-tracing) support
- [CachePlugin](./src/CachePlugin.ts) -- a full response cache
- [LoggerPlugin](./src/LoggerPlugin.ts) -- base level logging plugin
- [AuthPlugin](./src/AuthPlugin.ts) -- schema defined authorization levels
- [LocalizationPlugin](./src/L10nPlugin.ts) -- query level localization directiveYou can turn on the included [GraphQL playground](https://github.com/graphql/graphql-playground) by setting the `playgroundEndpoint` in the startup options.
## Getting started
Install using npm:
```console
$ npm add tiny-graphql-koa
```Example using plugins and the playground:
```typescript
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());
});
```