debian-mirror-gitlab/app/graphql/types/query_complexity_type.rb
2021-10-27 15:23:28 +05:30

31 lines
881 B
Ruby

# 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::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