Welcome to mirror list, hosted at ThFree Co, Russian Federation.

query_complexity_type.rb « types « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 13b618cf5cea8f814c5697497739c38b7f2799bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module Types
  # rubocop: disable Graphql/AuthorizeTypes
  class QueryComplexityType < ::Types::BaseObject
    graphql_name 'QueryComplexity'

    ANALYZER = GraphQL::Analysis::QueryComplexity.new { |_query, complexity| complexity }

    alias_method :query, :object

    field :limit, GraphQL::Types::Int,
          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::Types::Int,
          null: true,
          description: 'GraphQL query complexity score.'

    def score
      ::GraphQL::Analysis.analyze_query(query, [ANALYZER]).first
    end
  end
  # rubocop: enable Graphql/AuthorizeTypes
end