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-07-07 11:18:12 +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-07-31 22:56:46 +05:30
use Gitlab::Graphql::GenericTracing
2019-07-07 11:18:12 +05:30
query_analyzer Gitlab::Graphql::QueryAnalyzers::LogQueryComplexity.analyzer
2018-11-08 19:23:39 +05:30
query(Types::QueryType)
default_max_page_size 100
2019-07-07 11:18:12 +05:30
max_complexity DEFAULT_MAX_COMPLEXITY
2018-11-18 11:00:15 +05:30
mutation(Types::MutationType)
2019-07-07 11:18:12 +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