@@ -4,7 +4,11 @@ import { GraphQLSchema } from 'graphql/type/schema';
44import { Request , Response , NextFunction , RequestHandler } from 'express' ;
55import buildTypeWeightsFromSchema , { defaultTypeWeightsConfig } from '../analysis/buildTypeWeights' ;
66import setupRateLimiter from './rateLimiterSetup' ;
7- import { ExpressMiddlewareConfig , ExpressMiddlewareSet } from '../@types/expressMiddleware' ;
7+ import {
8+ ExpressMiddlewareConfig ,
9+ ExpressMiddlewareSet ,
10+ RequestWithVariables ,
11+ } from '../@types/expressMiddleware' ;
812import { RateLimiterResponse } from '../@types/rateLimit' ;
913import { connect } from '../utils/redis' ;
1014import ASTParser from '../analysis/ASTParser' ;
@@ -138,7 +142,16 @@ export default function expressGraphQLRateLimiter(
138142 next : NextFunction
139143 ) : Promise < void | Response < any , Record < string , any > > > => {
140144 const requestTimestamp = new Date ( ) . valueOf ( ) ;
141- const { query, variables } : { query : string ; variables : any } = req . body ;
145+ // access the query and variables passed to the server in the body or query string
146+ let query ;
147+ let variables ;
148+ if ( req . query ) {
149+ query = req . query . query ;
150+ variables = req . query . variables ;
151+ } else if ( req . body ) {
152+ query = req . body . query ;
153+ variables = req . body . variables ;
154+ }
142155 if ( ! query ) {
143156 console . error (
144157 'Error in expressGraphQLRateLimiter: There is no query on the request. Rate-Limiting skipped'
0 commit comments