We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e4f067a commit 84770f3Copy full SHA for 84770f3
src/index.ts
@@ -0,0 +1,22 @@
1
+import * as bodyParser from 'body-parser'
2
+import { Request, Response, NextFunction, RequestHandler } from 'express'
3
+
4
+export const bodyParserGraphQL: () => RequestHandler = () => (
5
+ req: Request,
6
+ res: Response,
7
+ next: NextFunction
8
+) => {
9
+ if (req.is('application/graphql')) {
10
+ bodyParser.text({ type: 'application/graphql' })(req, res, () => {
11
+ req.headers['content-type'] = 'application/json'
12
+ req.body = {
13
+ query: req.body
14
+ }
15
+ next()
16
+ })
17
+ } else {
18
+ bodyParser.json()(req, res, next)
19
20
+}
21
22
+export const graphql = bodyParserGraphQL
0 commit comments