Class: Resolvers::UserNotesCountResolver

Inherits:
BaseResolver
  • Object
show all
Includes:
Gitlab::Graphql::Authorize::AuthorizeResource
Defined in:
app/graphql/resolvers/user_notes_count_resolver.rb

Constant Summary

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #find_object, #raise_resource_not_available_error!

Methods inherited from BaseResolver

as_single, authorization, authorized?, before_connection_authorization, before_connection_authorization_block, calls_gitaly!, complexity, complexity_multiplier, #current_user, field_options, last, #object, #offset_pagination, requires_argument!, resolver_complexity, #select_result, single, #single?, single_definition_blocks, singular_type, when_single

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#authorized_resource?(object) ⇒ Boolean

Returns:

  • (Boolean)

21
22
23
24
# File 'app/graphql/resolvers/user_notes_count_resolver.rb', line 21

def authorized_resource?(object)
  ability = "read_#{object.class.name.underscore}".to_sym
  context[:current_user].present? && Ability.allowed?(context[:current_user], ability, object)
end

#resolveObject


9
10
11
12
13
14
15
16
17
18
19
# File 'app/graphql/resolvers/user_notes_count_resolver.rb', line 9

def resolve
  authorize!(object)

  BatchLoader::GraphQL.for(object.id).batch(key: :user_notes_count) do |ids, loader, args|
    counts = Note.count_for_collection(ids, object.class.name).index_by(&:noteable_id)

    ids.each do |id|
      loader.call(id, counts[id]&.count || 0)
    end
  end
end