diff options
Diffstat (limited to 'app/graphql/types/query_complexity_type.rb')
-rw-r--r-- | app/graphql/types/query_complexity_type.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/graphql/types/query_complexity_type.rb b/app/graphql/types/query_complexity_type.rb new file mode 100644 index 00000000000..82809fac22f --- /dev/null +++ b/app/graphql/types/query_complexity_type.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Types + # rubocop: disable Graphql/AuthorizeTypes + class QueryComplexityType < ::Types::BaseObject + ANALYZER = GraphQL::Analysis::QueryComplexity.new { |_query, complexity| complexity } + + graphql_name 'QueryComplexity' + + alias_method :query, :object + + field :limit, GraphQL::INT_TYPE, + null: true, + method: :max_complexity, + see: { + 'GitLab documentation on this limit' => + 'https://docs.gitlab.com/ee/api/graphql/index.html#max-query-complexity' + }, + description: 'GraphQL query complexity limit.' + + field :score, GraphQL::INT_TYPE, + null: true, + description: 'GraphQL query complexity score.' + + def score + ::GraphQL::Analysis.analyze_query(query, [ANALYZER]).first + end + end + # rubocop: enable Graphql/AuthorizeTypes +end |