Class: Types::Ci::Catalog::ResourceType

Inherits:
BaseObject
  • Object
show all
Defined in:
app/graphql/types/ci/catalog/resource_type.rb

Overview

rubocop: disable Graphql/AuthorizeTypes

Instance Method Summary collapse

Methods inherited from BaseObject

accepts, assignable?, authorization, authorization_scopes, authorize, authorized?, #current_user, #id

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Instance Method Details

#starrers_pathObject



70
71
72
# File 'app/graphql/types/ci/catalog/resource_type.rb', line 70

def starrers_path
  Gitlab::Routing.url_helpers.project_starrers_path(object.project)
end

#topicsObject

rubocop: disable GraphQL/ResolverMethodLength – this will be refactored: gitlab.com/gitlab-org/gitlab/-/issues/510648



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/graphql/types/ci/catalog/resource_type.rb', line 76

def topics
  BatchLoader::GraphQL.for(object).batch do |resources, loader|
    # rubocop: disable CodeReuse/ActiveRecord -- this is necessary to batch
    project_ids = resources.pluck(:project_id)
    project_topics = ::Projects::ProjectTopic.where(project_id: project_ids)
    topics = ::Projects::Topic.where(id: project_topics.pluck(:topic_id))
    grouped_project_topics = project_topics.group_by(&:project_id)

    resources.each do |resource|
      project_topics_ids_for_resource = grouped_project_topics.fetch(resource.project_id,
        []).pluck(:topic_id)
      topics_for_resource = topics.select { |topic| project_topics_ids_for_resource.include?(topic.id) }

      loader.call(resource, topics_for_resource.pluck(:name))
      # rubocop: enable CodeReuse/ActiveRecord
    end
  end
end

#web_pathObject



66
67
68
# File 'app/graphql/types/ci/catalog/resource_type.rb', line 66

def web_path
  ::Gitlab::Routing.url_helpers.project_path(object.project)
end