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

work_items_resolver.rb « namespaces « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54bb83920719d6f2d54c24ee03a27029cba6f9b3 (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
28
29
30
31
32
33
34
# frozen_string_literal: true

module Resolvers
  module Namespaces
    class WorkItemsResolver < BaseResolver
      prepend ::WorkItems::LookAheadPreloads

      type Types::WorkItemType.connection_type, null: true

      def resolve_with_lookahead(**args)
        return unless Feature.enabled?(:namespace_level_work_items, resource_parent)
        return WorkItem.none if resource_parent.nil?

        finder = ::WorkItems::NamespaceWorkItemsFinder.new(current_user, args.merge(
          namespace_id: resource_parent
        ))

        Gitlab::Graphql::Loaders::IssuableLoader.new(resource_parent, finder).batching_find_all do |q|
          apply_lookahead(q)
        end
      end

      private

      def resource_parent
        # The project could have been loaded in batch by `BatchLoader`.
        # At this point we need the `id` of the project to query for work items, so
        # make sure it's loaded and not `nil` before continuing.
        object.respond_to?(:sync) ? object.sync : object
      end
      strong_memoize_attr :resource_parent
    end
  end
end