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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2 KiB
Ruby
Raw Normal View History

2021-12-11 22:18:48 +05:30
# frozen_string_literal: true
module Resolvers
class BaseIssuesResolver < BaseResolver
prepend IssueResolverArguments
argument :sort, Types::IssueSortEnum,
description: 'Sort issues by this criteria.',
required: false,
default_value: :created_desc
2022-01-26 12:08:38 +05:30
argument :state, Types::IssuableStateEnum,
required: false,
description: 'Current state of this issue.'
2021-12-11 22:18:48 +05:30
2022-06-21 17:19:12 +05:30
# see app/graphql/types/issue_connection.rb
type 'Types::IssueConnection', null: true
2021-12-11 22:18:48 +05:30
NON_STABLE_CURSOR_SORTS = %i[priority_asc priority_desc
popularity_asc popularity_desc
label_priority_asc label_priority_desc
2022-06-21 17:19:12 +05:30
milestone_due_asc milestone_due_desc
escalation_status_asc escalation_status_desc].freeze
2021-12-11 22:18:48 +05:30
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
[
{
2022-01-12 12:59:36 +05:30
project: [:project_feature, :group]
2021-12-11 22:18:48 +05:30
},
:author
]
end
def preloads
{
alert_management_alert: [:alert_management_alert],
labels: [:labels],
assignees: [:assignees],
timelogs: [:timelogs],
2022-03-02 08:16:31 +05:30
customer_relations_contacts: { customer_relations_contacts: [:group] },
escalation_status: [:incident_management_issuable_escalation_status]
2021-12-11 22:18:48 +05:30
}
end
def non_stable_cursor_sort?(sort)
NON_STABLE_CURSOR_SORTS.include?(sort)
end
end
end
Resolvers::BaseIssuesResolver.prepend_mod_with('Resolvers::BaseIssuesResolver')