Rate and Query Complexity Limits
A complex GraphQL query can often be the equivalent of thousands of REST requests. Hence the AIRICA GraphQL API uses two mechanisms to limit rate and node limits: Rate Limiting and Query Complexity Limiting.
Rate Limiting#
If the number of API Requests over the course of a defined period of 30 seconds exceed the allowed limit, a RATE_LIMIT error will be thrown:
400 Bad Request{ "error": { "errors": [ { "message": "You executed more than 90 requests on the field 'client' within the last 30 seconds (rate limit exceeded). Please query API with a lower frequency.", "extensions": { "code": "RATE_LIMIT" } } ] }}Query Complexity Limiting#
The requested query cost is calculated before executing the query using static analysis. By identifying each type used in a query, we can calculate its cost.
First example#
query { client { buildings(first: 2000) { edges { node { name } } } }}The total number of 2000 requested buildings is too big. Make sure to reduce the number of requested items by using the pagination functionalities.
400 Bad Request{ "error": { "errors": [ { "message": "Query too complex: 6002. Max allowed complexity: 4000", "extensions": { "code": "QUERY_TOO_COMPLEX" } } ] }}Second example#
query { client { buildings(first: 200) { edges { node { rooms(first: 200) { edges { node { id name } } } } } } }}In this example, a total of 200 * 200 = 40000 could be queried. This results in a complexity score of over 100,000.
Especially queries with nested lists contribute to big complexity scores. We can either reduce the score by using pagination with lower values or by caching data. E.g. the room ids can be cached and a room can be used directly with the room query(/graphql/queries/room) can be used.
400 Bad Request{ "error": { "errors": [ { "message": "Query too complex: 120602. Max allowed complexity: 4000", "extensions": { "code": "QUERY_TOO_COMPLEX" } } ] }}