{"id":17512,"library":"body-parser-graphql","title":"Express GraphQL Request Body Parser","description":"body-parser-graphql is an Express.js middleware designed to process incoming HTTP requests with the `Content-Type` header set to `application/graphql`. Upon receipt, it transparently transforms the raw GraphQL query string from the request body into a standard `application/json` format, typically an object with a `query` property containing the GraphQL operation. This allows existing GraphQL server implementations, which usually expect `application/json` payloads, to seamlessly consume queries sent with the `application/graphql` Content-Type. The current stable version is 1.1.0, released in April 2018. However, the package has been archived and is no longer actively maintained as of March 2023, meaning users should consider alternatives or built-in solutions provided by modern GraphQL server libraries.","status":"abandoned","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/supergraphql/body-parser-graphql","tags":["javascript","graphql","express","typescript"],"install":[{"cmd":"npm install body-parser-graphql","lang":"bash","label":"npm"},{"cmd":"yarn add body-parser-graphql","lang":"bash","label":"yarn"},{"cmd":"pnpm add body-parser-graphql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for creating web servers and using middleware.","package":"express","optional":false},{"reason":"This package is a wrapper around the functionality of `body-parser`, providing the core parsing logic.","package":"body-parser","optional":false}],"imports":[{"note":"The primary middleware function is a named export.","wrong":"import bodyParserGraphQL from 'body-parser-graphql'","symbol":"bodyParserGraphQL","correct":"import { bodyParserGraphQL } from 'body-parser-graphql'"},{"note":"Imports all exports as a namespace. This is typically used to then access `bodyParser.graphql()`.","wrong":"const bodyParser = require('body-parser-graphql')","symbol":"* as bodyParser","correct":"import * as bodyParser from 'body-parser-graphql'"},{"note":"While TypeScript definitions exist, the package behavior aligns with named CommonJS exports for the main function.","wrong":"const bodyParserGraphQL = require('body-parser-graphql').default","symbol":"CommonJS require","correct":"const { bodyParserGraphQL } = require('body-parser-graphql')"}],"quickstart":{"code":"import * as express from 'express';\nimport { bodyParserGraphQL } from 'body-parser-graphql';\n\nconst app = express();\n\n// Integrate the GraphQL body parser middleware\napp.use(bodyParserGraphQL());\n\n// Example GraphQL endpoint (assuming a GraphQL server handler)\napp.post('/graphql', (req, res) => {\n  // req.body will now contain the parsed GraphQL query as a JSON object\n  // e.g., { query: \"{ posts { id title } }\" }\n  console.log('Received GraphQL query:', req.body.query);\n  res.json({\n    data: {\n      message: 'Hello from GraphQL endpoint!',\n      receivedQuery: req.body.query\n    }\n  });\n});\n\nconst port = process.env.PORT || 3000;\napp.listen(port, () => {\n  console.log(`Server running on http://localhost:${port}`);\n  console.log('Try sending a POST request to /graphql with Content-Type: application/graphql');\n  console.log('Body: { posts { id title } }');\n});","lang":"typescript","description":"Demonstrates setting up `body-parser-graphql` middleware in an Express application to handle `application/graphql` requests and access the parsed query on `req.body`."},"warnings":[{"fix":"Migrate to alternatives, such as `express-graphql` which includes its own body parsing capabilities, or handle `application/graphql` content-type manually in custom middleware.","message":"The `body-parser-graphql` package is no longer actively maintained. Its GitHub repository was archived on March 20, 2023, and is now read-only. This means there will be no further updates, bug fixes, or security patches.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Carefully test compatibility with your specific Express.js and Node.js versions. For long-term projects, consider alternatives that are actively maintained and integrated with modern frameworks.","message":"This package internally relies on `body-parser` functionality. While `body-parser` itself is actively maintained, this wrapper may use an older, fixed version of `body-parser` or have compatibility issues with newer versions of Express.js or Node.js without updates.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure clients send the raw GraphQL query string as the body with `Content-Type: application/graphql`. If clients send JSON, use standard `express.json()` middleware and ensure the `Content-Type` is `application/json`.","message":"The middleware expects a raw GraphQL query string in the request body when `Content-Type` is `application/graphql`. If the client sends a JSON object (e.g., `{ query: \"...\" }`) with `Content-Type: application/graphql`, it might not be parsed as expected, or could lead to errors. It converts `application/graphql` to `application/json` with the query string as the value of the `query` property.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure the middleware is called: `app.use(bodyParserGraphQL())` or `app.use(bodyParser.graphql())`.","cause":"The `bodyParserGraphQL` function was imported but not called, or the named export was incorrectly accessed.","error":"TypeError: app.use() requires a middleware function but got a undefined"},{"fix":"Verify the client is sending `Content-Type: application/graphql` and the GraphQL query string directly in the body. Ensure `app.use(bodyParserGraphQL())` is called early in your middleware stack.","cause":"This error usually indicates that `req.body` is empty because the `Content-Type` header was incorrect, or the middleware was not applied, or an upstream middleware consumed the body prematurely.","error":"POST body missing. Did you forget use body-parser middleware?"},{"fix":"Pass options to increase the limit, e.g., `app.use(bodyParserGraphQL({ limit: '5mb' }))`.","cause":"The incoming request body size exceeded the default limit configured for the underlying `body-parser` instance (typically 100kb).","error":"Error: request entity too large"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}