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

bulk_labels_resolver.rb « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7e9564352dbbd3662b0f72b8796bb0a639bd864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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)

      BatchLoader::GraphQL.for(object.id).batch(key: object.class.name, cache: false) do |ids, loader, args|
        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