Skip to content

Commit 7ac1b45

Browse files
committed
middleware can recieve queries encoded in the query string
1 parent 6d9be4e commit 7ac1b45

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/middleware/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { GraphQLSchema } from 'graphql/type/schema';
44
import { Request, Response, NextFunction, RequestHandler } from 'express';
55
import buildTypeWeightsFromSchema, { defaultTypeWeightsConfig } from '../analysis/buildTypeWeights';
66
import setupRateLimiter from './rateLimiterSetup';
7-
import { ExpressMiddlewareConfig, ExpressMiddlewareSet } from '../@types/expressMiddleware';
7+
import {
8+
ExpressMiddlewareConfig,
9+
ExpressMiddlewareSet,
10+
RequestWithVariables,
11+
} from '../@types/expressMiddleware';
812
import { RateLimiterResponse } from '../@types/rateLimit';
913
import { connect } from '../utils/redis';
1014
import 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

Comments
 (0)