body-parser-graphql
GraphQL server middleware to support application/graphql requests
Last updated 8 years ago by kbrandwijk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install body-parser-graphql 
SYNC missed versions from official npm registry.

body-parser-graphql npm

semantic-releaseCircleCICode ClimateCoverallsRenovate badge
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:

{
  posts {
    id
    title
  }
}

request.body value after the middleware:

{
  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:

$ 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.

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:

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

app.use(bodyParserGraphQL())

Current Tags

  • 1.1.0                                ...           latest (8 years ago)

2 Versions

  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (15)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |