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

60 lines
1.7 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,
2021-03-08 18:12:59 +05:30
description: 'Current state of this issue.'
2019-12-21 20:55:43 +05:30
argument :sort, Types::IssueSortEnum,
2021-03-08 18:12:59 +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
2021-09-30 23:02:18 +05:30
popularity_asc popularity_desc
2020-05-24 23:13:21 +05:30
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)
2021-03-08 18:12:59 +05:30
issues = Gitlab::Graphql::Loaders::IssuableLoader.new(parent, finder).batching_find_all { |q| apply_lookahead(q) }
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
2021-03-08 18:12:59 +05:30
def unconditional_includes
[
{
project: [:project_feature]
}
]
end
2020-11-24 15:15:51 +05:30
def preloads
{
alert_management_alert: [:alert_management_alert],
labels: [:labels],
2021-04-29 21:17:54 +05:30
assignees: [:assignees],
timelogs: [:timelogs]
2020-11-24 15:15:51 +05:30
}
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
2021-06-08 01:23:25 +05:30
Resolvers::IssuesResolver.prepend_mod_with('Resolvers::IssuesResolver')