# graphql-api-koa

> GraphQL execution and error handling middleware written from scratch for Koa.

Latest version **9.1.3** (published 2022-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-api-koa
pnpm add graphql-api-koa
yarn add graphql-api-koa
bun add graphql-api-koa
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 9.1.3 |
| Published | 2022-11-06 |
| First published | 2018-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/graphql-api-koa) |
| Module format | ESM + CommonJS |
| Node | ^14.17.0 \|\| ^16.0.0 \|\| >= 18.0.0 |
| Dependencies | 3 |
| Unpacked size | 28.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Jayden Seric |
| Maintainers | jaydenseric |
| Keywords | graphql, api, koa, esm, mjs |

## Links

- npm: https://www.npmjs.com/package/graphql-api-koa
- Repository: https://github.com/jaydenseric/graphql-api-koa
- Homepage: https://github.com/jaydenseric/graphql-api-koa#readme
- Issues: https://github.com/jaydenseric/graphql-api-koa/issues
- Funding: https://github.com/sponsors/jaydenseric
- npm.io page: https://npm.io/package/graphql-api-koa

## Dependencies (3)

- [@types/koa](https://npm.io/package/@types/koa.md) ^2.13.5
- [http-errors](https://npm.io/package/http-errors.md) ^2.0.0
- [@types/http-errors](https://npm.io/package/@types/http-errors.md) ^2.0.1

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 9.1.3 (latest) — 2022-11-06
- 9.1.2 — 2022-11-04
- 9.1.1 — 2022-09-01
- 9.1.0 — 2022-07-04
- 9.0.0 — 2022-06-28
- 8.0.0 — 2021-11-04
- 7.0.0 — 2021-05-07
- 6.0.0 — 2020-06-06
- 5.1.0 — 2020-06-01
- 5.0.0 — 2020-05-17
- 4.1.2 — 2020-04-27
- 4.1.1 — 2020-01-14
- 4.1.0 — 2020-01-07
- 4.0.0 — 2019-12-28
- 3.0.0 — 2019-12-28
- … 11 more at https://npm.io/package/graphql-api-koa/versions

## README

![graphql-api-koa logo](https://cdn.jsdelivr.net/gh/jaydenseric/graphql-api-koa@1.1.1/graphql-api-koa-logo.svg)

# graphql-api-koa

[GraphQL](https://graphql.org) execution and error handling middleware written from scratch for [Koa](https://koajs.com).

## Installation

To install [`graphql-api-koa`](https://npm.im/graphql-api-koa) and its [`graphql`](https://npm.im/graphql) peer dependency with [npm](https://npmjs.com/get-npm), run:

```sh
npm install graphql-api-koa graphql
```

Setup the Koa middleware in this order:

1. [`errorHandler`](./errorHandler.mjs), to catch errors from following middleware for a correctly formatted [GraphQL response](https://spec.graphql.org/October2021/#sec-Errors).
2. A [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec) processor like `graphqlUploadKoa` from [`graphql-upload`](https://npm.im/graphql-upload), to support file uploads (optional).
3. A request body parser like [`koa-bodyparser`](https://npm.im/koa-bodyparser).
4. [`execute`](./execute.mjs), to execute GraphQL.

See the [`execute`](./execute.mjs) middleware examples to get started.

## Requirements

Supported runtime environments:

- [Node.js](https://nodejs.org) versions `^14.17.0 || ^16.0.0 || >= 18.0.0`.

Projects must configure [TypeScript](https://typescriptlang.org) to use types from the ECMAScript modules that have a `// @ts-check` comment:

- [`compilerOptions.allowJs`](https://typescriptlang.org/tsconfig#allowJs) should be `true`.
- [`compilerOptions.maxNodeModuleJsDepth`](https://typescriptlang.org/tsconfig#maxNodeModuleJsDepth) should be reasonably large, e.g. `10`.
- [`compilerOptions.module`](https://typescriptlang.org/tsconfig#module) should be `"node16"` or `"nodenext"`.

## Exports

The [npm](https://npmjs.com) package [`graphql-api-koa`](https://npm.im/graphql-api-koa) features [optimal JavaScript module design](https://jaydenseric.com/blog/optimal-javascript-module-design). It doesn’t have a main index module, so use deep imports from the ECMAScript modules that are exported via the [`package.json`](./package.json) field [`exports`](https://nodejs.org/api/packages.html#exports):

- [`errorHandler.mjs`](./errorHandler.mjs)
- [`execute.mjs`](./execute.mjs)
- [`GraphQLAggregateError.mjs`](./GraphQLAggregateError.mjs)

---
_Source: https://npm.io/package/graphql-api-koa · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
