Class: Resolvers::MergeRequestsCountResolver

Inherits:
BaseResolver
  • Object
show all
Defined in:
app/graphql/resolvers/merge_requests_count_resolver.rb

Instance Method Summary collapse

Methods inherited from BaseResolver

as_single, authorization, authorized?, before_connection_authorization, before_connection_authorization_block, calculate_ext_conn_complexity, calls_gitaly!, calls_gitaly?, complexity, complexity_multiplier, #current_user, last, #offset_pagination, requires_argument!, 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!

Instance Method Details

#objectObject

We call this resolver from ‘IssueType` where object is an `Issue` instance, and we also call this resolver from `Widgets::DevelopmentType`, in which case the object is a connection type, so we need to get its respective work item.



20
21
22
23
24
25
26
27
# File 'app/graphql/resolvers/merge_requests_count_resolver.rb', line 20

def object
  case super
  when ::GraphQL::Pagination::Connection
    super.try(:parent)&.work_item
  else
    super
  end
end

#resolveObject



7
8
9
10
11
12
13
14
15
# File 'app/graphql/resolvers/merge_requests_count_resolver.rb', line 7

def resolve
  BatchLoader::GraphQL.for(object.id).batch do |ids, loader, args|
    counts = MergeRequestsClosingIssues.count_for_collection(ids, context[:current_user]).to_h

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