Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaydenseric/graphql-api-koa
GraphQL execution and error handling middleware written from scratch for Koa.
https://github.com/jaydenseric/graphql-api-koa
api graphql koa maintained node npm
Last synced: about 1 month ago
JSON representation
GraphQL execution and error handling middleware written from scratch for Koa.
- Host: GitHub
- URL: https://github.com/jaydenseric/graphql-api-koa
- Owner: jaydenseric
- License: mit
- Created: 2018-05-11T10:11:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-06T23:56:15.000Z (about 2 years ago)
- Last Synced: 2024-10-10T12:41:27.052Z (2 months ago)
- Topics: api, graphql, koa, maintained, node, npm
- Language: JavaScript
- Homepage: https://npm.im/graphql-api-koa
- Size: 290 KB
- Stars: 52
- Watchers: 5
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Funding: .github/funding.yml
- License: license.md
Awesome Lists containing this project
- awesome-graphql - graphql-api-koa - GraphQL Koa middleware that implements GraphQL.js from scratch and supports native ESM. (Libraries / JavaScript Libraries)
- awesome-graphql - graphql-api-koa - GraphQL Koa middleware that implements GraphQL.js from scratch and supports native ESM. (Implementations / JavaScript/TypeScript)
- awesome-graphql - graphql-api-koa - GraphQL Koa middleware that implements GraphQL.js from scratch and supports native ESM. (Libraries / JavaScript Libraries)
README
![graphql-api-koa logo](https://cdn.jsdelivr.net/gh/jaydenseric/[email protected]/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)