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

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

64 lines
1.9 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Resolvers
2023-01-13 00:05:48 +05:30
class IssuesResolver < Issues::BaseResolver
2023-05-27 22:25:52 +05:30
extend ::Gitlab::Utils::Override
2023-01-13 00:05:48 +05:30
prepend ::Issues::LookAheadPreloads
include ::Issues::SortArguments
2023-05-27 22:25:52 +05:30
NON_FILTER_ARGUMENTS = %i[sort lookahead include_archived].freeze
2023-03-17 16:20:25 +05:30
2023-05-27 22:25:52 +05:30
argument :include_archived, GraphQL::Types::Boolean,
required: false,
default_value: false,
description: 'Whether to include issues from archived projects. Defaults to `false`.'
2023-01-13 00:05:48 +05:30
argument :state, Types::IssuableStateEnum,
2023-05-27 22:25:52 +05:30
required: false,
description: 'Current state of this issue.'
2023-01-13 00:05:48 +05:30
# see app/graphql/types/issue_connection.rb
type 'Types::IssueConnection', null: true
2023-03-04 22:38:38 +05:30
before_connection_authorization do |nodes, current_user|
projects = nodes.map(&:project)
::Preloaders::UserMaxAccessLevelInProjectsPreloader.new(projects, current_user).execute
2023-04-23 21:23:45 +05:30
::Preloaders::GroupPolicyPreloader.new(projects.filter_map(&:group), current_user).execute
2023-03-04 22:38:38 +05:30
end
2023-03-17 16:20:25 +05:30
def ready?(**args)
unless filter_provided?(args)
raise Gitlab::Graphql::Errors::ArgumentError, _('You must provide at least one filter argument for this query')
end
super
end
2023-01-13 00:05:48 +05:30
def resolve_with_lookahead(**args)
issues = apply_lookahead(
IssuesFinder.new(current_user, prepare_finder_params(args)).execute
)
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
2023-03-17 16:20:25 +05:30
private
2023-05-27 22:25:52 +05:30
override :prepare_finder_params
def prepare_finder_params(args)
super.tap do |prepared|
prepared[:non_archived] = !prepared.delete(:include_archived)
end
end
2023-03-17 16:20:25 +05:30
def filter_provided?(args)
args.except(*NON_FILTER_ARGUMENTS).values.any?(&:present?)
end
2019-02-15 15:39:39 +05:30
end
end