SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Allow to limit the execution time of GraphQL queries #487

Closed ujibang closed 1 year ago

ujibang commented 1 year ago

Brief overview

Allow to limit the GraphQL queries execution by setting a time limit.

If a query execution time exceeds the time limit, 408 Request timeout should be returned with following error message:

{
  "errors": [
    {
      "message": "Maximum query time limit of 20ms exceeded",
      "extensions": { "classification": "ExecutionAborted" }
    }
  ]
}

Rationale

Avoid GraphQL queries that consume too much resources.

Detailed documentation

The GraphQL configuration parameter query-time-limit specifies the time limit in milliseconds for processing queries. Set to 0 for no time limit.

Example:

The following command starts RESTHeart overriding the configuration paramenter /graphql/query-time-limit setting a limit of 10s for GraphQL queries execution:

$  RHO="/graphql/query-time-limit->10000" java -jar core/target/restheart.jar
ujibang commented 1 year ago

Done in 7.6.3