debian-mirror-gitlab/app/graphql/resolvers/issues_resolver.rb

50 lines
1.5 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Resolvers
class IssuesResolver < BaseResolver
2020-11-24 15:15:51 +05:30
prepend IssueResolverArguments
2019-02-15 15:39:39 +05:30
2019-07-07 11:18:12 +05:30
argument :state, Types::IssuableStateEnum,
required: false,
2020-01-01 13:55:28 +05:30
description: 'Current state of this issue'
2019-12-21 20:55:43 +05:30
argument :sort, Types::IssueSortEnum,
2019-12-04 20:38:33 +05:30
description: 'Sort issues by this criteria',
2019-02-15 15:39:39 +05:30
required: false,
2021-02-22 17:27:13 +05:30
default_value: :created_desc
2019-02-15 15:39:39 +05:30
2021-01-29 00:20:46 +05:30
type Types::IssueType.connection_type, null: true
2019-02-15 15:39:39 +05:30
2020-05-24 23:13:21 +05:30
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc
label_priority_asc label_priority_desc
milestone_due_asc milestone_due_desc].freeze
2020-10-24 23:57:45 +05:30
def continue_issue_resolve(parent, finder, **args)
2020-11-24 15:15:51 +05:30
issues = apply_lookahead(Gitlab::Graphql::Loaders::IssuableLoader.new(parent, finder).batching_find_all)
2020-05-24 23:13:21 +05:30
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.
2021-02-22 17:27:13 +05:30
offset_pagination(issues)
2020-05-24 23:13:21 +05:30
else
issues
end
2019-02-15 15:39:39 +05:30
end
2019-07-31 22:56:46 +05:30
2020-11-24 15:15:51 +05:30
private
def preloads
{
alert_management_alert: [:alert_management_alert],
labels: [:labels],
assignees: [:assignees]
}
end
2020-05-24 23:13:21 +05:30
def non_stable_cursor_sort?(sort)
NON_STABLE_CURSOR_SORTS.include?(sort)
end
2019-02-15 15:39:39 +05:30
end
end
2020-07-28 23:09:34 +05:30
Resolvers::IssuesResolver.prepend_if_ee('::EE::Resolvers::IssuesResolver')