# All files index.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 9/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    321x

    1x

    4x
    3x
    3x
    3x

    3x

    1x

    1x
     import * as bodyParser from 'body-parser'
    import { Request, Response, NextFunction, RequestHandler } from 'express'

    export interface BodyParserJSONOptions {
      limit?: number | string,
      inflate?: boolean,
      reviver?: any,
      strict?: boolean,
      type?: string,
      verify?: any,
    }

    export const bodyParserGraphQL: (options?: BodyParserJSONOptions) => RequestHandler = (options?: BodyParserJSONOptions) => (
      req: Request,
      res: Response,
      next: NextFunction
    ) => {
      if (req.is('application/graphql')) {
        bodyParser.text({ type: 'application/graphql' })(req, res, () => {
          req.headers['content-type'] = 'application/json'
          req.body = {
            query: req.body
          }
          next()
        })
      } else {
        bodyParser.json(options)(req, res, next)
      }
    }

    export const graphql = bodyParserGraphQL