Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

body-parser-graphql

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-parser-graphql

GraphQL server middleware to support application/graphql requests

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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())

Keywords

FAQs

Package last updated on 26 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc