Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
},
"plugins": ["import", "prettier"],
"rules": {

"no-plusplus": [2, {
"allowForLoopAfterthoughts": true
}],
"prettier/prettier": [
"error"
]
},
"ignorePatterns": ["jest.config.js"]
"ignorePatterns": ["jest.config.ts"]
}
7 changes: 0 additions & 7 deletions jest.config.js

This file was deleted.

11 changes: 11 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
verbose: true,
roots: ['./test'],
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['js', 'ts'],
};

export default config;
237 changes: 237 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "1.0.0",
"description": "A GraphQL rate limiting library using query complexity analysis.",
"main": "index.js",
"type": "module",
"scripts": {
"test": "jest --passWithNoTests",
"lint": "eslint src test",
"lint:fix": "eslint --fix src test",
"lint:fix": "eslint --fix src test @types",
"prettier": "prettier --write .",
"prepare": "husky install"
},
Expand Down Expand Up @@ -43,6 +44,7 @@
"prettier": "2.6.2",
"redis-mock": "^0.56.3",
"ts-jest": "^28.0.2",
"ts-node": "^10.8.0",
"typescript": "^4.6.4"
},
"lint-staged": {
Expand Down
4 changes: 3 additions & 1 deletion src/@types/rateLimit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ interface TokenBucketOptions {
}

// TODO: This will be a union type where we can specify Option types for other Rate Limiters
type RateLimiterOptions = TokenBucketOptions;
// Record<string, never> represents the empty object for alogorithms that don't require settings
// and might be able to be removed in the future.
type RateLimiterOptions = TokenBucketOptions | Record<string, never>;
4 changes: 2 additions & 2 deletions src/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { defaultTypeWeightsConfig } from '../analysis/buildTypeWeights';
* Defaults to {mutation: 10, object: 1, field: 0, connection: 2}
* @returns {RequestHandler} express middleware that computes the complexity of req.query and calls the next middleware
* if the query is allowed or sends a 429 status if the request is blocked
* @throws ValidationError if GraphQL Schema is invalid
* FIXME: How about the specific GraphQLError?
* @throws ValidationError if GraphQL Schema is invalid.
*/
export function expressRateLimiter(
rateLimiter: RateLimiterSelection,
Expand All @@ -31,7 +32,6 @@ export function expressRateLimiter(
// TODO: Connect to Redis store using provided options. Default to localhost:6379
// TODO: Configure the selected RateLimtier
// TODO: Configure the complexity analysis algorithm to run for incoming requests

const middleware: RequestHandler = (req: Request, res: Response, next: NextFunction) => {
// TODO: Parse query from req.query, compute complexity and pass necessary info to rate limiter
// TODO: Call next if query is successful, send 429 status if query blocked, call next(err) with any thrown errors
Expand Down
Loading