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

97 lines
3.9 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Resolvers
class IssuesResolver < BaseResolver
2019-09-04 21:01:54 +05:30
argument :iid, GraphQL::STRING_TYPE,
2019-07-07 11:18:12 +05:30
required: false,
2020-01-01 13:55:28 +05:30
description: 'IID of the issue. For example, "1"'
2019-02-15 15:39:39 +05:30
2019-09-04 21:01:54 +05:30
argument :iids, [GraphQL::STRING_TYPE],
2019-03-02 22:35:43 +05:30
required: false,
2020-01-01 13:55:28 +05:30
description: 'List of IIDs of issues. For example, [1, 2]'
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-07-07 11:18:12 +05:30
argument :label_name, GraphQL::STRING_TYPE.to_list_type,
required: false,
2020-01-01 13:55:28 +05:30
description: 'Labels applied to this issue'
2020-04-08 14:13:33 +05:30
argument :milestone_title, GraphQL::STRING_TYPE.to_list_type,
required: false,
description: 'Milestones applied to this issue'
argument :assignee_username, GraphQL::STRING_TYPE,
required: false,
description: 'Username of a user assigned to the issues'
argument :assignee_id, GraphQL::STRING_TYPE,
required: false,
description: 'ID of a user assigned to the issues, "none" and "any" values supported'
2019-07-07 11:18:12 +05:30
argument :created_before, Types::TimeType,
required: false,
2019-12-04 20:38:33 +05:30
description: 'Issues created before this date'
2019-07-07 11:18:12 +05:30
argument :created_after, Types::TimeType,
required: false,
2019-12-04 20:38:33 +05:30
description: 'Issues created after this date'
2019-07-07 11:18:12 +05:30
argument :updated_before, Types::TimeType,
required: false,
2019-12-04 20:38:33 +05:30
description: 'Issues updated before this date'
2019-07-07 11:18:12 +05:30
argument :updated_after, Types::TimeType,
required: false,
2019-12-04 20:38:33 +05:30
description: 'Issues updated after this date'
2019-07-07 11:18:12 +05:30
argument :closed_before, Types::TimeType,
required: false,
2019-12-04 20:38:33 +05:30
description: 'Issues closed before this date'
2019-07-07 11:18:12 +05:30
argument :closed_after, Types::TimeType,
required: false,
2019-12-04 20:38:33 +05:30
description: 'Issues closed after this date'
2020-01-01 13:55:28 +05:30
argument :search, GraphQL::STRING_TYPE,
required: false,
2020-07-28 23:09:34 +05:30
description: 'Search query for issue title or description'
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,
default_value: 'created_desc'
type Types::IssueType, null: true
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
2019-02-15 15:39:39 +05:30
def resolve(**args)
2019-07-31 22:56:46 +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
2019-09-04 21:01:54 +05:30
# make sure it's loaded and not `nil` before continuing.
2020-04-22 19:07:51 +05:30
parent = object.respond_to?(:sync) ? object.sync : object
return Issue.none if parent.nil?
2019-02-15 15:39:39 +05:30
# Will need to be be made group & namespace aware with
2019-12-04 20:38:33 +05:30
# https://gitlab.com/gitlab-org/gitlab-foss/issues/54520
2020-07-28 23:09:34 +05:30
args[:iids] ||= [args.delete(:iid)].compact if args[:iid]
args[:attempt_project_search_optimizations] = true if args[:search].present?
2019-02-15 15:39:39 +05:30
2020-07-28 23:09:34 +05:30
finder = IssuesFinder.new(current_user, args)
issues = 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.
Gitlab::Graphql::Pagination::OffsetActiveRecordRelationConnection.new(issues)
else
issues
end
2019-02-15 15:39:39 +05:30
end
2019-07-31 22:56:46 +05:30
2019-09-04 21:01:54 +05:30
def self.resolver_complexity(args, child_complexity:)
2019-07-31 22:56:46 +05:30
complexity = super
complexity += 2 if args[:labelName]
complexity
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')