2021-09-30 23:02:18 +05: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
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
field :limit, GraphQL::Types::Int,
|
2021-09-30 23:02:18 +05:30
|
|
|
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.'
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
field :score, GraphQL::Types::Int,
|
2021-09-30 23:02:18 +05:30
|
|
|
null: true,
|
|
|
|
description: 'GraphQL query complexity score.'
|
|
|
|
|
|
|
|
def score
|
|
|
|
::GraphQL::Analysis.analyze_query(query, [ANALYZER]).first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop: enable Graphql/AuthorizeTypes
|
|
|
|
end
|