SoftInstigate / restheart

Open Source Low-code API development framework Featuring ready-to-go Security and MongoDB API
http://softinstigate.github.io/restheart/
GNU Affero General Public License v3.0
792 stars 170 forks source link

Allow to limit the execution time of GraphQL queries #487

Closed ujibang closed 7 months ago

ujibang commented 7 months 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 7 months ago

Done in 7.6.3