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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcharlieablett <cablett@gitlab.com>2019-06-16 13:12:56 +0300
committercharlieablett <cablett@gitlab.com>2019-07-03 13:53:13 +0300
commit8b809837f44bbebdac65eebadb09a45fb60c6a65 (patch)
treef4c4d929f6dcd74c939290eaf1d79f809b6032fe /app/graphql/types
parent9b06890d1d6901b840fb321c9b99264c2e8813f7 (diff)
Enumerate fields with Gitaly calls
- Add a complexity of 1 if Gitaly is called at least once - Add an error notification if `calls_gitaly` isn't right for a particular field
Diffstat (limited to 'app/graphql/types')
-rw-r--r--app/graphql/types/base_field.rb23
-rw-r--r--app/graphql/types/project_type.rb2
-rw-r--r--app/graphql/types/tree/tree_type.rb4
3 files changed, 25 insertions, 4 deletions
diff --git a/app/graphql/types/base_field.rb b/app/graphql/types/base_field.rb
index dd0d9105df6..ee23146f711 100644
--- a/app/graphql/types/base_field.rb
+++ b/app/graphql/types/base_field.rb
@@ -4,21 +4,30 @@ module Types
class BaseField < GraphQL::Schema::Field
prepend Gitlab::Graphql::Authorize
+ attr_reader :calls_gitaly
+
DEFAULT_COMPLEXITY = 1
def initialize(*args, **kwargs, &block)
+ @calls_gitaly = !!kwargs.delete(:calls_gitaly)
kwargs[:complexity] ||= field_complexity(kwargs[:resolver_class])
super(*args, **kwargs, &block)
end
+ def base_complexity
+ complexity = DEFAULT_COMPLEXITY
+ complexity += 1 if @calls_gitaly
+ complexity
+ end
+
private
def field_complexity(resolver_class)
if resolver_class
field_resolver_complexity
else
- DEFAULT_COMPLEXITY
+ base_complexity
end
end
@@ -45,5 +54,17 @@ module Types
complexity.to_i
end
end
+
+ def calls_gitaly_check
+ # Will inform you if :calls_gitaly should be true or false based on the number of Gitaly calls
+ # involved with the request.
+ if @calls_gitaly && Gitlab::GitalyClient.get_request_count == 0
+ raise "Gitaly is called for field '#{name}' - please add `calls_gitaly: true` to the field declaration"
+ elsif !@calls_gitaly && Gitlab::GitalyClient.get_request_count > 0
+ raise "Gitaly not called for field '#{name}' - please remove `calls_gitaly: true` from the field declaration"
+ end
+ rescue => e
+ Gitlab::Sentry.track_exception(e)
+ end
end
end
diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb
index c25688ab043..87d5351f80f 100644
--- a/app/graphql/types/project_type.rb
+++ b/app/graphql/types/project_type.rb
@@ -26,7 +26,7 @@ module Types
field :web_url, GraphQL::STRING_TYPE, null: true
field :star_count, GraphQL::INT_TYPE, null: false
- field :forks_count, GraphQL::INT_TYPE, null: false
+ field :forks_count, GraphQL::INT_TYPE, null: false, calls_gitaly: true # 4 times
field :created_at, Types::TimeType, null: true
field :last_activity_at, Types::TimeType, null: true
diff --git a/app/graphql/types/tree/tree_type.rb b/app/graphql/types/tree/tree_type.rb
index b947713074e..2023abc13f9 100644
--- a/app/graphql/types/tree/tree_type.rb
+++ b/app/graphql/types/tree/tree_type.rb
@@ -15,9 +15,9 @@ module Types
Gitlab::Graphql::Representation::TreeEntry.decorate(obj.trees, obj.repository)
end
- field :submodules, Types::Tree::SubmoduleType.connection_type, null: false
+ field :submodules, Types::Tree::SubmoduleType.connection_type, null: false, calls_gitaly: true
- field :blobs, Types::Tree::BlobType.connection_type, null: false, resolve: -> (obj, args, ctx) do
+ field :blobs, Types::Tree::BlobType.connection_type, null: false, calls_gitaly: true, resolve: -> (obj, args, ctx) do
Gitlab::Graphql::Representation::TreeEntry.decorate(obj.blobs, obj.repository)
end
# rubocop: enable Graphql/AuthorizeTypes