2022-02-01 18:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module WorkItems
|
|
|
|
class Delete < BaseMutation
|
2022-02-15 12:14:49 +00:00
|
|
|
graphql_name 'WorkItemDelete'
|
2022-02-01 18:17:05 +00:00
|
|
|
description "Deletes a work item." \
|
2022-05-30 21:09:18 +00:00
|
|
|
" Available only when feature flag `work_items` is enabled."
|
2022-02-01 18:17:05 +00:00
|
|
|
|
|
|
|
authorize :delete_work_item
|
|
|
|
|
|
|
|
argument :id, ::Types::GlobalIDType[::WorkItem],
|
|
|
|
required: true,
|
|
|
|
description: 'Global ID of the work item.'
|
|
|
|
|
|
|
|
field :project, Types::ProjectType,
|
|
|
|
null: true,
|
|
|
|
description: 'Project the deleted work item belonged to.'
|
|
|
|
|
|
|
|
def resolve(id:)
|
|
|
|
work_item = authorized_find!(id: id)
|
|
|
|
|
2022-03-23 15:08:38 +00:00
|
|
|
unless work_item.project.work_items_feature_flag_enabled?
|
2022-02-01 18:17:05 +00:00
|
|
|
return { errors: ['`work_items` feature flag disabled for this project'] }
|
|
|
|
end
|
|
|
|
|
|
|
|
result = ::WorkItems::DeleteService.new(
|
|
|
|
project: work_item.project,
|
|
|
|
current_user: current_user
|
|
|
|
).execute(work_item)
|
|
|
|
|
|
|
|
{
|
|
|
|
project: result.success? ? work_item.project : nil,
|
|
|
|
errors: result.errors
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_object(id:)
|
|
|
|
GitlabSchema.find_by_gid(id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|