Class: Mutations::WorkItems::Hierarchy::AddChildrenItems

Inherits:
BaseMutation
  • Object
show all
Includes:
Widgetable
Defined in:
app/graphql/mutations/work_items/hierarchy/add_children_items.rb

Constant Summary

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods included from Widgetable

#extract_widget_params!

Methods inherited from BaseMutation

#api_user?, authorization, authorization_scopes, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

Instance Method Details

#resolve(id:, **attributes) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/graphql/mutations/work_items/hierarchy/add_children_items.rb', line 28

def resolve(id:, **attributes)
  Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/408575')

  work_item = authorized_find!(id: id)
  children = attributes[:children]

  widget_attributes = { hierarchy_widget: { children: children } }
  widget_params = extract_widget_params!(work_item.work_item_type, widget_attributes, work_item.resource_parent)

  update_result = ::WorkItems::UpdateService.new(
    container: work_item.resource_parent,
    current_user: current_user,
    params: {},
    widget_params: widget_params
  ).execute(work_item)

  # Find newly added children using the provided children_ids
  if update_result[:status] == :success
    updated_work_item = update_result[:work_item]
    children_ids = children.map(&:id)
    added_children = updated_work_item.work_item_children.select { |child| children_ids.include?(child.id) }
  else
    added_children = []
  end

  {
    added_children: added_children,
    errors: Array.wrap(update_result[:message])
  }
end