Commit 8d8ff533 authored by Alex Kalderimis's avatar Alex Kalderimis

Annotate resolvers that call gitaly

The following resolvers call gitaly:

- metrics/dashboard_resolver
- last_commit_resolver
- snippets/blobs_resolver
- tree_resolver

Remove an unnecessary gitaly annotation (I was unable to verify that
this gitaly annotation was needed. So it is removed.)
parent e300fad5
...@@ -12,8 +12,17 @@ module Resolvers ...@@ -12,8 +12,17 @@ module Resolvers
@requires_argument = true @requires_argument = true
end end
def self.calls_gitaly!
@calls_gitaly = true
end
def self.field_options def self.field_options
super.merge(requires_argument: @requires_argument) extra_options = {
requires_argument: @requires_argument,
calls_gitaly: @calls_gitaly
}.compact
super.merge(extra_options)
end end
def self.singular_type def self.singular_type
......
...@@ -4,6 +4,8 @@ module Resolvers ...@@ -4,6 +4,8 @@ module Resolvers
class LastCommitResolver < BaseResolver class LastCommitResolver < BaseResolver
type Types::CommitType, null: true type Types::CommitType, null: true
calls_gitaly!
alias_method :tree, :object alias_method :tree, :object
def resolve(**args) def resolve(**args)
......
...@@ -3,19 +3,30 @@ ...@@ -3,19 +3,30 @@
module Resolvers module Resolvers
module Metrics module Metrics
class DashboardResolver < Resolvers::BaseResolver class DashboardResolver < Resolvers::BaseResolver
type Types::Metrics::DashboardType, null: true
calls_gitaly!
argument :path, GraphQL::STRING_TYPE, argument :path, GraphQL::STRING_TYPE,
required: true, required: true,
description: "Path to a file which defines metrics dashboard eg: 'config/prometheus/common_metrics.yml'." description: "Path to a file which defines metrics dashboard " \
"eg: 'config/prometheus/common_metrics.yml'."
type Types::Metrics::DashboardType, null: true
alias_method :environment, :object alias_method :environment, :object
def resolve(**args) def resolve(**args)
return unless environment return unless environment
::PerformanceMonitoring::PrometheusDashboard ::PerformanceMonitoring::PrometheusDashboard.find_for(**args, **service_params)
.find_for(project: environment.project, user: context[:current_user], path: args[:path], options: { environment: environment }) end
private
def service_params
{
project: environment.project,
user: current_user,
options: { environment: environment }
}
end end
end end
end end
......
...@@ -8,6 +8,7 @@ module Resolvers ...@@ -8,6 +8,7 @@ module Resolvers
type Types::Snippets::BlobType.connection_type, null: true type Types::Snippets::BlobType.connection_type, null: true
authorize :read_snippet authorize :read_snippet
calls_gitaly!
alias_method :snippet, :object alias_method :snippet, :object
......
...@@ -4,6 +4,8 @@ module Resolvers ...@@ -4,6 +4,8 @@ module Resolvers
class TreeResolver < BaseResolver class TreeResolver < BaseResolver
type Types::Tree::TreeType, null: true type Types::Tree::TreeType, null: true
calls_gitaly!
argument :path, GraphQL::STRING_TYPE, argument :path, GraphQL::STRING_TYPE,
required: false, required: false,
default_value: '', default_value: '',
......
...@@ -14,7 +14,6 @@ module Types ...@@ -14,7 +14,6 @@ module Types
field :plain_data, GraphQL::STRING_TYPE, field :plain_data, GraphQL::STRING_TYPE,
description: 'Blob plain highlighted data.', description: 'Blob plain highlighted data.',
calls_gitaly: true,
null: true null: true
field :raw_path, GraphQL::STRING_TYPE, field :raw_path, GraphQL::STRING_TYPE,
......
...@@ -15,6 +15,7 @@ module Types ...@@ -15,6 +15,7 @@ module Types
field :web_path, GraphQL::STRING_TYPE, null: true, field :web_path, GraphQL::STRING_TYPE, null: true,
description: 'Web path of the blob.' description: 'Web path of the blob.'
field :lfs_oid, GraphQL::STRING_TYPE, null: true, field :lfs_oid, GraphQL::STRING_TYPE, null: true,
calls_gitaly: true,
description: 'LFS ID of the blob.' description: 'LFS ID of the blob.'
field :mode, GraphQL::STRING_TYPE, null: true, field :mode, GraphQL::STRING_TYPE, null: true,
description: 'Blob mode in numeric format.' description: 'Blob mode in numeric format.'
......
...@@ -79,7 +79,7 @@ module Gitlab ...@@ -79,7 +79,7 @@ module Gitlab
end end
def field_name def field_name
"#{field.owner_type.graphql_name}.#{field.graphql_name}" "#{field.owner.graphql_name}.#{field.graphql_name}"
end end
end end
end end
......
...@@ -38,7 +38,10 @@ module GraphqlHelpers ...@@ -38,7 +38,10 @@ module GraphqlHelpers
# All resolution goes through fields, so we need to create one here that # All resolution goes through fields, so we need to create one here that
# uses our resolver. Thankfully, apart from the field name, resolvers # uses our resolver. Thankfully, apart from the field name, resolvers
# contain all the configuration needed to define one. # contain all the configuration needed to define one.
field_options = resolver_class.field_options.merge(name: 'field_value') field_options = resolver_class.field_options.merge(
owner: resolver_parent,
name: 'field_value'
)
field = ::Types::BaseField.new(**field_options) field = ::Types::BaseField.new(**field_options)
# All mutations accept a single `:input` argument. Wrap arguments here. # All mutations accept a single `:input` argument. Wrap arguments here.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment