# body-parser-graphql

> GraphQL server middleware to support application/graphql requests

Latest version **1.1.0** (published 2018-04-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install body-parser-graphql
pnpm add body-parser-graphql
yarn add body-parser-graphql
bun add body-parser-graphql
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-04-26 |
| First published | 2018-01-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 157.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Kim Brandwijk |
| Maintainers | kbrandwijk |
| Keywords | graphql, express |

## Links

- npm: https://www.npmjs.com/package/body-parser-graphql
- Repository: https://github.com/supergraphql/body-parser-graphql
- Homepage: https://github.com/supergraphql/body-parser-graphql#readme
- Issues: https://github.com/supergraphql/body-parser-graphql/issues
- npm.io page: https://npm.io/package/body-parser-graphql

## Dependencies (1)

- [body-parser](https://npm.io/package/body-parser.md) ^1.18.2

## 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

- 1.1.0 (latest) — 2018-04-26
- 1.0.0 — 2018-01-01

## README

# body-parser-graphql [![npm](https://img.shields.io/npm/v/body-parser-graphql.svg?style=for-the-badge)](https://www.npmjs.com/package/body-parser-graphql)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge)](https://github.com/semantic-release/semantic-release)[![CircleCI](https://img.shields.io/circleci/project/github/supergraphql/body-parser-graphql.svg?style=for-the-badge)](https://circleci.com/gh/supergraphql/body-parser-graphql)[![Code Climate](https://img.shields.io/codeclimate/maintainability/supergraphql/body-parser-graphql.svg?style=for-the-badge&label=code%20quality)](https://codeclimate.com/github/supergraphql/body-parser-graphql)[![Coveralls](https://img.shields.io/coveralls/github/supergraphql/body-parser-graphql.svg?style=for-the-badge)](https://coveralls.io/github/supergraphql/body-parser-graphql)[![Renovate badge](https://img.shields.io/badge/renovate-enabled-e10079.svg?style=for-the-badge)](https://renovateapp.com/)  
Express body-parser that supports the `application/graphql` MIME type.

## How does it work?
`body-parser-graphql` checks the `Content-Type` header of the request. If the Content-Type is `application/graphql`, the request is transformed into a 'normal' `application/json` GraphQL request, and the `Content-Type` header is set to `application/json`.

Received request:
```graphql
{
  posts {
    id
    title
  }
}
```
`request.body` value after the middleware:
```js
{
  query: {
    posts {
      id
      title
    }
  }
}
```

If an `application/json` request is received, it applies the JSON body-parser.

## Installation

Install `body-parser-graphql` using your favorite package manager:
```shell
$ yarn add body-parser-graphql
$ npm install body-parser-graphql
```

## Usage

The `body-parser-graphql` can be used as a drop-in replacement for the normal `json` body-parser.

```diff
import * as express from 'express'
- import * as bodyParser from 'body-parser'
+ import * as bodyParser from 'body-parser-graphql'

const app = express()

- app.use(bodyParser.json())
+ app.use(bodyParser.graphql())

// Your express routes

app.listen(/* your configuration */)
```

Alternatively, you can also import the body-parser directly:

```typescript
import { bodyParserGraphQL } from 'body-parser-graphql'

app.use(bodyParserGraphQL())
```

<hr>
<p align="center">
  <img src="https://img.shields.io/badge/built-with_%F0%9F%92%99-blue.svg?style=for-the-badge"/><a href="https://github.com/kbrandwijk" target="-_blank"><img src="https://img.shields.io/badge/by-kim_brandwijk-blue.svg?style=for-the-badge"/></a>
</p>

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