diff options
Diffstat (limited to 'app/graphql/resolvers/bulk_labels_resolver.rb')
-rw-r--r-- | app/graphql/resolvers/bulk_labels_resolver.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/graphql/resolvers/bulk_labels_resolver.rb b/app/graphql/resolvers/bulk_labels_resolver.rb new file mode 100644 index 00000000000..7362e257fb6 --- /dev/null +++ b/app/graphql/resolvers/bulk_labels_resolver.rb @@ -0,0 +1,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(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 |