Skip to content

Commit 3ac1c94

Browse files
committed
refactored middleware and complexityAnalysis to use variables
1 parent 4074bc8 commit 3ac1c94

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/analysis/typeComplexityAnalysis.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import { parse } from 'graphql';
1515
* @param {TypeWeightObject} typeWeights
1616
* @param {string} complexityOption
1717
*/
18-
function getQueryTypeComplexity(queryString: string, typeWeights: TypeWeightObject): number {
18+
function getQueryTypeComplexity(
19+
queryString: string,
20+
queryVariables: any,
21+
typeWeights: TypeWeightObject
22+
): number {
1923
throw Error('getQueryComplexity is not implemented.');
2024
}
2125

src/middleware/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function expressRateLimiter(
4242
// return the rate limiting middleware
4343
return async (req: Request, res: Response, next: NextFunction): Promise<void> => {
4444
const requestTimestamp = new Date().valueOf();
45-
const { query }: { query: string } = req.body;
45+
const { query, variables }: { query: string; variables: any } = req.body;
4646
if (!query) {
4747
// FIXME: Throw an error here? Code currently passes this on to whatever is next
4848
console.log('There is no query on the request');
@@ -62,7 +62,7 @@ export function expressRateLimiter(
6262
const ip: string = req.ips[0] || req.ip;
6363

6464
// FIXME: this will only work with type complexity
65-
const queryComplexity = getQueryTypeComplexity(query, typeWeightObject);
65+
const queryComplexity = getQueryTypeComplexity(query, variables, typeWeightObject);
6666

6767
try {
6868
// process the request and conditinoally respond to client with status code 429 o

0 commit comments

Comments
 (0)