2019-12-13 09:08:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Snippets
|
|
|
|
class Destroy < Base
|
|
|
|
graphql_name 'DestroySnippet'
|
|
|
|
|
|
|
|
ERROR_MSG = 'Error deleting the snippet'
|
|
|
|
|
2020-11-09 21:08:48 +00:00
|
|
|
argument :id, ::Types::GlobalIDType[::Snippet],
|
2019-12-13 09:08:01 +00:00
|
|
|
required: true,
|
2020-12-04 00:09:55 +00:00
|
|
|
description: 'The global ID of the snippet to destroy'
|
2019-12-13 09:08:01 +00:00
|
|
|
|
|
|
|
def resolve(id:)
|
|
|
|
snippet = authorized_find!(id: id)
|
|
|
|
|
2020-01-17 00:09:00 +00:00
|
|
|
response = ::Snippets::DestroyService.new(current_user, snippet).execute
|
|
|
|
errors = response.success? ? [] : [ERROR_MSG]
|
2019-12-13 09:08:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
errors: errors
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ability_name
|
|
|
|
"admin"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|