debian-mirror-gitlab/app/graphql/resolvers/concerns/issue_resolver_arguments.rb

113 lines
4.4 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
2020-11-24 15:15:51 +05:30
module IssueResolverArguments
2020-10-24 23:57:45 +05:30
extend ActiveSupport::Concern
prepended do
2020-11-24 15:15:51 +05:30
include LooksAhead
2020-10-24 23:57:45 +05:30
argument :iid, GraphQL::STRING_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'IID of the issue. For example, "1".'
2020-10-24 23:57:45 +05:30
argument :iids, [GraphQL::STRING_TYPE],
required: false,
2021-03-08 18:12:59 +05:30
description: 'List of IIDs of issues. For example, [1, 2].'
2021-04-29 21:17:54 +05:30
argument :label_name, [GraphQL::STRING_TYPE, null: true],
2020-10-24 23:57:45 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Labels applied to this issue.'
2021-04-29 21:17:54 +05:30
argument :milestone_title, [GraphQL::STRING_TYPE, null: true],
2020-10-24 23:57:45 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Milestone applied to this issue.'
2021-01-03 14:25:43 +05:30
argument :author_username, GraphQL::STRING_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Username of the author of the issue.'
2020-10-24 23:57:45 +05:30
argument :assignee_username, GraphQL::STRING_TYPE,
required: false,
2021-04-29 21:17:54 +05:30
description: 'Username of a user assigned to the issue.',
deprecated: { reason: 'Use `assigneeUsernames`', milestone: '13.11' }
2021-01-03 14:25:43 +05:30
argument :assignee_usernames, [GraphQL::STRING_TYPE],
required: false,
2021-03-08 18:12:59 +05:30
description: 'Usernames of users assigned to the issue.'
2020-10-24 23:57:45 +05:30
argument :assignee_id, GraphQL::STRING_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'ID of a user assigned to the issues, "none" and "any" values are supported.'
2020-10-24 23:57:45 +05:30
argument :created_before, Types::TimeType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Issues created before this date.'
2020-10-24 23:57:45 +05:30
argument :created_after, Types::TimeType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Issues created after this date.'
2020-10-24 23:57:45 +05:30
argument :updated_before, Types::TimeType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Issues updated before this date.'
2020-10-24 23:57:45 +05:30
argument :updated_after, Types::TimeType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Issues updated after this date.'
2020-10-24 23:57:45 +05:30
argument :closed_before, Types::TimeType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Issues closed before this date.'
2020-10-24 23:57:45 +05:30
argument :closed_after, Types::TimeType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Issues closed after this date.'
2020-10-24 23:57:45 +05:30
argument :search, GraphQL::STRING_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Search query for issue title or description.'
2020-10-24 23:57:45 +05:30
argument :types, [Types::IssueTypeEnum],
as: :issue_types,
2021-03-08 18:12:59 +05:30
description: 'Filter issues by the given issue types.',
2020-10-24 23:57:45 +05:30
required: false
2021-04-29 21:17:54 +05:30
argument :not, Types::Issues::NegatedIssueFilterInputType,
description: 'List of negated params.',
prepare: ->(negated_args, ctx) { negated_args.to_h },
required: false
2020-10-24 23:57:45 +05:30
end
2020-11-24 15:15:51 +05:30
def resolve_with_lookahead(**args)
2020-10-24 23:57:45 +05:30
# The project could have been loaded in batch by `BatchLoader`.
# At this point we need the `id` of the project to query for issues, so
# make sure it's loaded and not `nil` before continuing.
parent = object.respond_to?(:sync) ? object.sync : object
return Issue.none if parent.nil?
# Will need to be made group & namespace aware with
# https://gitlab.com/gitlab-org/gitlab-foss/issues/54520
args[:iids] ||= [args.delete(:iid)].compact if args[:iid]
args[:attempt_project_search_optimizations] = true if args[:search].present?
2021-04-29 21:17:54 +05:30
prepare_assignee_username_params(args)
2020-10-24 23:57:45 +05:30
finder = IssuesFinder.new(current_user, args)
continue_issue_resolve(parent, finder, **args)
end
2021-04-29 21:17:54 +05:30
def ready?(**args)
if args.slice(*mutually_exclusive_assignee_username_args).compact.size > 1
arg_str = mutually_exclusive_assignee_username_args.map { |x| x.to_s.camelize(:lower) }.join(', ')
raise Gitlab::Graphql::Errors::ArgumentError, "only one of [#{arg_str}] arguments is allowed at the same time."
end
super
end
2020-10-24 23:57:45 +05:30
class_methods do
def resolver_complexity(args, child_complexity:)
complexity = super
complexity += 2 if args[:labelName]
complexity
end
end
2021-04-29 21:17:54 +05:30
private
def prepare_assignee_username_params(args)
args[:assignee_username] = args.delete(:assignee_usernames) if args[:assignee_usernames].present?
args[:not][:assignee_username] = args[:not].delete(:assignee_usernames) if args.dig(:not, :assignee_usernames).present?
end
def mutually_exclusive_assignee_username_args
[:assignee_usernames, :assignee_username]
end
2020-10-24 23:57:45 +05:30
end