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
request.body value after the middleware:
application/json request is received, it applies the JSON body-parser.
body-parser-graphql using your favorite package manager:
$ yarn add body-parser-graphql$ npm install body-parser-graphql
body-parser-graphql can be used as a drop-in replacement for the normal
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 routesapp.listen(/* your configuration */)
Alternatively, you can also import the body-parser directly: