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
One of the biggest challenges posed by applications built on GraphQL is that a single path manages all queries to the server, and every request is usually a `POST` operation.
344
+
Preventing server overload for GraphQL APIs can be different from preventing overload for RESTful APIs. One of the biggest challenges posed by applications built on GraphQL is that a single path manages all queries to the server, and every request is usually a `POST` operation. This prevents different rate limits for different API use cases based on the HTTP method and URI path.
345
345
346
-
The purpose of the request is usually embedded in the body, which has information on what data the client wants to fetch or mutate (according to [GraphQL's terminology](https://graphql.org/learn/queries/) for server-side data modification), along with any additional data required to carry out the action.
346
+
However, instead of using the method and path like a RESTful API, the purpose of the request is usually embedded in the body, which has information on what data the client wants to fetch or mutate (according to [GraphQL's terminology](https://graphql.org/learn/queries/) for server-side data modification), along with any additional data required to carry out the action.
347
+
348
+
To prevent server overload, consider the following approaches:
349
+
350
+
1. Limit the number of times a particular user can call the same GraphQL operation name.
351
+
2. Limit the total amount of query complexity any given user is allowed to request.
352
+
3. Limit any individual request's query complexity.
347
353
348
354
The following examples are based on an application that accepts reviews for movies. A GraphQL request could look like the following:
349
355
@@ -376,7 +382,7 @@ To limit the rate of actions, you could use the following rule:
376
382
377
383
_This example rule requires Advanced Rate Limiting and payload inspection._
378
384
379
-
### Prevent server overload
385
+
### Limit the total amount of query complexity
380
386
381
387
The complexity necessary to handle a GraphQL request can vary significantly. Since the API uses a single endpoint, it is difficult to figure out the complexity of each request before it has been served.
382
388
@@ -405,7 +411,7 @@ Currently, you can only create complexity-based (or score-based) rules such as t
405
411
406
412
When the origin server processes a request, it adds a `score` HTTP header to the response with a value representing how much work the origin has performed to handle it — for example, `400`. In the next hour, the same client can perform requests up to an additional budget of `600`. As soon as this budget is exceeded, later requests will be blocked until the timeout expires.
407
413
408
-
### GraphQL malicious query protection
414
+
### Limit any individual query’s complexity
409
415
410
416
API Shield customers can use GraphQL malicious query protection to protect their GraphQL APIs. GraphQL malicious query protection scans your GraphQL traffic for queries that could overload your origin and result in a denial of service. You can build rules that limit the query depth and size of incoming GraphQL queries in order to block suspiciously large or complex queries.
0 commit comments