debian-mirror-gitlab/app/graphql/gitlab_schema.rb

44 lines
1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
class GitlabSchema < GraphQL::Schema
2019-05-18 00:54:41 +05:30
# Currently an IntrospectionQuery has a complexity of 179.
# These values will evolve over time.
DEFAULT_MAX_COMPLEXITY = 200
AUTHENTICATED_COMPLEXITY = 250
ADMIN_COMPLEXITY = 300
2018-11-08 19:23:39 +05:30
use BatchLoader::GraphQL
use Gitlab::Graphql::Authorize
use Gitlab::Graphql::Present
use Gitlab::Graphql::Connections
2019-05-18 00:54:41 +05:30
use Gitlab::Graphql::Tracing
query_analyzer Gitlab::Graphql::QueryAnalyzers::LogQueryComplexity.analyzer
2018-11-08 19:23:39 +05:30
query(Types::QueryType)
default_max_page_size 100
2019-05-18 00:54:41 +05:30
max_complexity DEFAULT_MAX_COMPLEXITY
2018-11-18 11:00:15 +05:30
mutation(Types::MutationType)
2019-05-18 00:54:41 +05:30
def self.execute(query_str = nil, **kwargs)
kwargs[:max_complexity] ||= max_query_complexity(kwargs[:context])
super(query_str, **kwargs)
end
def self.max_query_complexity(ctx)
current_user = ctx&.fetch(:current_user, nil)
if current_user&.admin
ADMIN_COMPLEXITY
elsif current_user
AUTHENTICATED_COMPLEXITY
else
DEFAULT_MAX_COMPLEXITY
end
end
2018-11-08 19:23:39 +05:30
end