summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/issues_resolver.rb
blob: 396ae02ae1304a659fdf342eb1b8539fcd66b84d (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
# 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, 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 = apply_lookahead(Gitlab::Graphql::Loaders::IssuableLoader.new(parent, finder).batching_find_all)

      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.
        Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection.new(issues)
      else
        issues
      end
    end

    private

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

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

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