summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/work_items_resolver.rb
blob: 055984db3cb135e739ea11b9b683873291ed2759 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

module Resolvers
  class WorkItemsResolver < BaseResolver
    include SearchArguments
    include LooksAhead

    type Types::WorkItemType.connection_type, null: true

    argument :iid, GraphQL::Types::String,
             required: false,
             description: 'IID of the issue. For example, "1".'
    argument :iids, [GraphQL::Types::String],
             required: false,
             description: 'List of IIDs of work items. For example, `["1", "2"]`.'
    argument :sort, Types::WorkItemSortEnum,
             description: 'Sort work items by this criteria.',
             required: false,
             default_value: :created_desc
    argument :state, Types::IssuableStateEnum,
             required: false,
             description: 'Current state of this work item.'
    argument :types, [Types::IssueTypeEnum],
             as: :issue_types,
             description: 'Filter work items by the given work item types.',
             required: false

    def resolve_with_lookahead(**args)
      # The project could have been loaded in batch by `BatchLoader`.
      # At this point we need the `id` of the project to query for issues, so
      # make sure it's loaded and not `nil` before continuing.
      parent = object.respond_to?(:sync) ? object.sync : object
      return WorkItem.none if parent.nil? || !parent.work_items_feature_flag_enabled?

      args[:iids] ||= [args.delete(:iid)].compact if args[:iid]
      args[:attempt_project_search_optimizations] = true if args[:search].present?

      finder = ::WorkItems::WorkItemsFinder.new(current_user, args)

      Gitlab::Graphql::Loaders::IssuableLoader.new(parent, finder).batching_find_all { |q| apply_lookahead(q) }
    end

    def ready?(**args)
      validate_anonymous_search_access! if args[:search].present?

      super
    end

    private

    def unconditional_includes
      [
        {
          project: [:project_feature, :group]
        },
        :author
      ]
    end
  end
end

Resolvers::WorkItemsResolver.prepend_mod_with('Resolvers::WorkItemsResolver')