2020-10-30 14:08:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Todos
|
|
|
|
class Create < ::Mutations::Todos::Base
|
|
|
|
graphql_name 'TodoCreate'
|
|
|
|
|
|
|
|
authorize :create_todo
|
|
|
|
|
|
|
|
argument :target_id,
|
|
|
|
Types::GlobalIDType[Todoable],
|
|
|
|
required: true,
|
2021-08-17 20:11:18 -04:00
|
|
|
description: "Global ID of the to-do item's parent. Issues, merge requests, designs, and epics are supported."
|
2020-10-30 14:08:56 -04:00
|
|
|
|
|
|
|
field :todo, Types::TodoType,
|
|
|
|
null: true,
|
2021-08-17 20:11:18 -04:00
|
|
|
description: 'To-do item created.'
|
2020-10-30 14:08:56 -04:00
|
|
|
|
|
|
|
def resolve(target_id:)
|
2022-05-10 14:08:27 -04:00
|
|
|
target = authorized_find!(target_id)
|
2020-10-30 14:08:56 -04:00
|
|
|
|
|
|
|
todo = TodoService.new.mark_todo(target, current_user)&.first
|
|
|
|
errors = errors_on_object(todo) if todo
|
|
|
|
|
|
|
|
{
|
|
|
|
todo: todo,
|
|
|
|
errors: errors
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_object(id)
|
|
|
|
GitlabSchema.find_by_gid(id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|