2022-07-23 23:45:48 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class WorkItemsResolver < BaseResolver
|
|
|
|
include SearchArguments
|
|
|
|
include LooksAhead
|
2023-05-27 22:25:52 +05:30
|
|
|
include ::WorkItems::SharedFilterArguments
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
argument :iid,
|
|
|
|
GraphQL::Types::String,
|
|
|
|
required: false,
|
|
|
|
description: 'IID of the work item. For example, "1".'
|
|
|
|
argument :sort,
|
|
|
|
Types::WorkItemSortEnum,
|
|
|
|
description: 'Sort work items by criteria.',
|
|
|
|
required: false,
|
|
|
|
default_value: :created_desc
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
type Types::WorkItemType.connection_type, null: true
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
def resolve_with_lookahead(**args)
|
2023-01-13 00:05:48 +05:30
|
|
|
return WorkItem.none if resource_parent.nil?
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
finder = ::WorkItems::WorkItemsFinder.new(current_user, prepare_finder_params(args))
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
Gitlab::Graphql::Loaders::IssuableLoader.new(resource_parent, finder).batching_find_all { |q| apply_lookahead(q) }
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
private
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
def preloads
|
|
|
|
{
|
2022-11-25 23:54:43 +05:30
|
|
|
work_item_type: :work_item_type,
|
2023-06-20 00:43:36 +05:30
|
|
|
web_url: { namespace: :route, project: [:project_namespace, { namespace: :route }] },
|
2023-04-23 21:23:45 +05:30
|
|
|
widgets: { work_item_type: :enabled_widget_definitions }
|
2022-10-11 01:57:18 +05:30
|
|
|
}
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def nested_preloads
|
|
|
|
{
|
|
|
|
widgets: widget_preloads,
|
2023-04-23 21:23:45 +05:30
|
|
|
user_permissions: { update_work_item: :assignees },
|
|
|
|
project: { jira_import_status: { project: :jira_imports } },
|
|
|
|
author: {
|
|
|
|
location: { author: :user_detail },
|
|
|
|
gitpod_enabled: { author: :user_preference }
|
|
|
|
}
|
2022-11-25 23:54:43 +05:30
|
|
|
}
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def widget_preloads
|
|
|
|
{
|
|
|
|
last_edited_by: :last_edited_by,
|
|
|
|
assignees: :assignees,
|
|
|
|
parent: :work_item_parent,
|
2023-04-23 21:23:45 +05:30
|
|
|
children: { work_item_children_by_relative_position: [:author, { project: :project_feature }] },
|
2023-01-13 00:05:48 +05:30
|
|
|
labels: :labels,
|
2023-05-27 22:25:52 +05:30
|
|
|
milestone: { milestone: [:project, :group] },
|
2023-06-20 00:43:36 +05:30
|
|
|
subscribed: [:assignees, :award_emoji, { notes: [:author, :award_emoji] }],
|
|
|
|
award_emoji: { award_emoji: :awardable }
|
2022-11-25 23:54:43 +05:30
|
|
|
}
|
2022-10-11 01:57:18 +05:30
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
def unconditional_includes
|
|
|
|
[
|
|
|
|
{
|
|
|
|
project: [:project_feature, :group]
|
|
|
|
},
|
|
|
|
:author
|
|
|
|
]
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
def prepare_finder_params(args)
|
|
|
|
params = super(args)
|
|
|
|
params[:iids] ||= [params.delete(:iid)].compact if params[:iid]
|
|
|
|
|
|
|
|
params
|
|
|
|
end
|
|
|
|
|
|
|
|
def resource_parent
|
|
|
|
# The project could have been loaded in batch by `BatchLoader`.
|
|
|
|
# At this point we need the `id` of the project to query for work items, so
|
|
|
|
# make sure it's loaded and not `nil` before continuing.
|
|
|
|
strong_memoize(:resource_parent) do
|
|
|
|
object.respond_to?(:sync) ? object.sync : object
|
|
|
|
end
|
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
Resolvers::WorkItemsResolver.prepend_mod_with('Resolvers::WorkItemsResolver')
|