debian-mirror-gitlab/app/graphql/resolvers/users/group_count_resolver.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
620 B
Ruby
Raw Permalink Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module Resolvers
module Users
class GroupCountResolver < BaseResolver
2021-10-27 15:23:28 +05:30
type GraphQL::Types::Int, null: true
2021-02-22 17:27:13 +05:30
2021-01-29 00:20:46 +05:30
alias_method :user, :object
def resolve(**args)
return unless can_read_group_count?
BatchLoader::GraphQL.for(user.id).batch do |user_ids, loader|
results = UserGroupsCounter.new(user_ids).execute
results.each do |user_id, count|
loader.call(user_id, count)
end
end
end
def can_read_group_count?
current_user&.can?(:read_group_count, user)
end
end
end
end