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.
npm install body-parser-graphqlVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up `body-parser-graphql` middleware in an Express application to handle `application/graphql` requests and access the parsed query on `req.body`.
Migrate to alternatives, such as `express-graphql` which includes its own body parsing capabilities, or handle `application/graphql` content-type manually in custom middleware.
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.
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`.
Ensure the middleware is called: `app.use(bodyParserGraphQL())` or `app.use(bodyParser.graphql())`.
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.
Pass options to increase the limit, e.g., `app.use(bodyParserGraphQL({ limit: '5mb' }))`.