1.0.0 • Published 5 years ago

koa-bodyparser-graphql v1.0.0

Weekly downloads
34
License
ISC
Repository
-
Last release
5 years ago

koa-bodyparser-graphql

Koa body-parser that supports the application/graphql MIME type.

How does it work?

koa-bodyparser-graphql checks the Content-Type header of the request. If the Content-Type is application/graphql, it will get the request info and pack it into normal body.

Received request:

{
	books {
		title
		author
	}
}

ctx.request.body value after the middleware:

{
  query: {
    {
	    books {
		    title
		    author
	    }
    }
  }
}

If an application/json request is received, it applies the JSON koa-bodyparser.

Installation

Install koa-bodyparser-graphql using your favorite package manager:

$ yarn add koa-bodyparser-graphql
$ npm install koa-bodyparser-graphql

Usage

The koa-bodyparser-graphql can be used as a drop-in replacement for the normal json koa-bodyparser.

const Koa = require('koa')
- const bodyparser = require('koa-bodyparser');
+ const bodyparser = require('koa-bodyparser-graphql');
const app = new Koa();

app.use(bodyparser());
// Your koa routes
app.listen(/* your configuration */)

That's all!