You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* /// "ratelimiter" must be explicitly specified in the setup of the middleware.
17
-
* /// "redis" connection options (https://ioredis.readthedocs.io/en/stable/API/#new_Redis) and an optional "keyExpiry" property (defaults to 24h)
18
-
* /// "typeWeights" optional type weight configuration for the GraphQL Schema. Developers can override default typeWeights. Defaults to {mutation: 10, query: 1, object: 1, scalar/enum: 0, connection: 2}
19
-
* /// "dark: true" will run the package in "dark mode" to monitor queries and rate limiting data before implementing rate limitng functionality. Defaults to false
20
-
* /// "enforceBoundedLists: true" will throw an error if any lists in the schema are not constrained by slicing arguments: Defaults to false
21
-
* /// "depthLimit: number" will block queries with deeper nesting than the specified depth. Will not block queries by depth by default
16
+
* , "ratelimiter" must be explicitly specified in the setup of the middleware.
17
+
* , "redis" connection options (https://ioredis.readthedocs.io/en/stable/API/#new_Redis) and an optional "keyExpiry" property (defaults to 24h)
18
+
* , "typeWeights" optional type weight configuration for the GraphQL Schema. Developers can override default typeWeights. Defaults to {mutation: 10, query: 1, object: 1, scalar/enum: 0, connection: 2}
19
+
* , "dark: true" will run the package in "dark mode" to monitor queries and rate limiting data before implementing rate limitng functionality. Defaults to false
20
+
* , "enforceBoundedLists: true" will throw an error if any lists in the schema are not constrained by slicing arguments: Defaults to false
21
+
* , "depthLimit: number" will block queries with deeper nesting than the specified depth. Will not block queries by depth by default
22
22
* @returns {RequestHandler} express middleware that computes the complexity of req.query and calls the next middleware
23
23
* if the query is allowed or sends a 429 status if the request is blocked
24
24
* FIXME: How about the specific GraphQLError?
25
-
* @throwsValidationError if GraphQL Schema is invalid.
25
+
* @throwsError
26
26
*/
27
27
exportdefaultfunctionexpressGraphQLRateLimiter(
28
28
schema: GraphQLSchema,
@@ -46,34 +46,38 @@ export default function expressGraphQLRateLimiter(
@@ -128,6 +132,7 @@ export default function expressGraphQLRateLimiter(
128
132
});
129
133
}
130
134
135
+
/** Rate-limiting middleware */
131
136
returnasync(
132
137
req: Request,
133
138
res: Response,
@@ -145,9 +150,9 @@ export default function expressGraphQLRateLimiter(
145
150
constip: string=req.ips ? req.ips[0] : req.ip;
146
151
147
152
constqueryAST=parse(query);
148
-
// validate the query against the schema. The GraphQL validation function returns an array of errors.
153
+
// validate the query against the schema. returns an array of errors.
149
154
constvalidationErrors=validate(schema,queryAST);
150
-
// check if the length of the returned GraphQL Errors array is greater than zero. If it is, there were errors. Call next so that the GraphQL server can handle those.
155
+
// return the errors to the client if the array has length. otherwise there are no errors
151
156
if(validationErrors.length>0){
152
157
res.status(400).json({errors: validationErrors});
153
158
}
@@ -156,8 +161,6 @@ export default function expressGraphQLRateLimiter(
0 commit comments