'How to retrieve a GitLab GraphQL's query complexity?
Is there any way to retrieve what the query complexity is for a GitLab GraphQL query?
As a comparison, GitHub's GraphQL api has a rateLimit object that returns the "cost" of a query https://docs.github.com/en/graphql/overview/resource-limitations. Does GitLab have anything similar?
If this capability does not exist, how can one compute the complexity of a query?
Solution 1:[1]
Not sure when this was implemented, but you can now query the complexity and limit, as described in the docs and reference https://docs.gitlab.com/ee/api/graphql/reference/#queryquerycomplexity
Example query:
{
queryComplexity {
limit
score
}
}
Example response:
{
"data": {
"queryComplexity": {
"limit": 300,
"score": 3
}
}
}
Solution 2:[2]
https://docs.gitlab.com/ee/api/graphql/index.html#max-query-complexity
There is no way to discover the complexity of a query except by exceeding the limit.
If a query exceeds the complexity limit an error message response will be returned.
In general, each field in a query will add 1 to the complexity score, although this can be higher or lower for particular fields. Sometimes the addition of certain arguments may also increase the complexity of a query.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | todinov |
| Solution 2 | Peter Pezaris |
