2022-11-25 23:54:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class BulkLabelsResolver < BaseResolver
|
|
|
|
include Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
|
|
|
|
type Types::LabelType.connection_type, null: true
|
|
|
|
|
|
|
|
def resolve
|
|
|
|
authorize!(object)
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
BatchLoader::GraphQL.for(object.id).batch(key: object.class.name, cache: false) do |ids, loader, args|
|
2022-11-25 23:54:43 +05:30
|
|
|
labels = Label.for_targets(object.class.id_in(ids)).group_by(&:target_id)
|
|
|
|
|
|
|
|
ids.each do |id|
|
|
|
|
loader.call(id, labels[id] || [])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authorized_resource?(object)
|
|
|
|
Ability.allowed?(current_user, :read_label, object.issuing_parent)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|