summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/issues_resolver.rb
blob: 7a67f115abfcb17d15bd60a91f2034e7c0374df9 (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
# frozen_string_literal: true

module Resolvers
  class IssuesResolver < BaseResolver
    prepend IssueResolverArguments

    argument :state, Types::IssuableStateEnum,
              required: false,
              description: 'Current state of this issue.'
    argument :sort, Types::IssueSortEnum,
              description: 'Sort issues by this criteria.',
              required: false,
              default_value: :created_desc

    type Types::IssueType.connection_type, null: true

    NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc
                                 label_priority_asc label_priority_desc
                                 milestone_due_asc milestone_due_desc].freeze

    def continue_issue_resolve(parent, finder, **args)
      issues = Gitlab::Graphql::Loaders::IssuableLoader.new(parent, finder).batching_find_all { |q| apply_lookahead(q) }

      if non_stable_cursor_sort?(args[:sort])
        # Certain complex sorts are not supported by the stable cursor pagination yet.
        # In these cases, we use offset pagination, so we return the correct connection.
        offset_pagination(issues)
      else
        issues
      end
    end

    private

    def unconditional_includes
      [
        {
          project: [:project_feature]
        }
      ]
    end

    def preloads
      {
        alert_management_alert: [:alert_management_alert],
        labels: [:labels],
        assignees: [:assignees],
        timelogs: [:timelogs]
      }
    end

    def non_stable_cursor_sort?(sort)
      NON_STABLE_CURSOR_SORTS.include?(sort)
    end
  end
end

Resolvers::IssuesResolver.prepend_if_ee('::EE::Resolvers::IssuesResolver')