debian-mirror-gitlab/app/graphql/mutations/snippets/update.rb

67 lines
1.9 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
module Mutations
module Snippets
class Update < Base
graphql_name 'UpdateSnippet'
argument :id,
GraphQL::ID_TYPE,
required: true,
description: 'The global id of the snippet to update'
argument :title, GraphQL::STRING_TYPE,
required: false,
description: 'Title of the snippet'
argument :file_name, GraphQL::STRING_TYPE,
required: false,
description: 'File name of the snippet'
argument :content, GraphQL::STRING_TYPE,
required: false,
description: 'Content of the snippet'
argument :description, GraphQL::STRING_TYPE,
required: false,
description: 'Description of the snippet'
argument :visibility_level, Types::VisibilityLevelsEnum,
description: 'The visibility level of the snippet',
required: false
2020-07-28 23:09:34 +05:30
argument :files, [Types::Snippets::FileInputType],
description: 'The snippet files to update',
required: false
2020-01-01 13:55:28 +05:30
def resolve(args)
snippet = authorized_find!(id: args.delete(:id))
2020-03-09 13:42:32 +05:30
result = ::Snippets::UpdateService.new(snippet.project,
2020-07-28 23:09:34 +05:30
context[:current_user],
update_params(args)).execute(snippet)
2020-03-09 13:42:32 +05:30
snippet = result.payload[:snippet]
2020-01-01 13:55:28 +05:30
{
2020-03-09 13:42:32 +05:30
snippet: result.success? ? snippet : snippet.reset,
2020-01-01 13:55:28 +05:30
errors: errors_on_object(snippet)
}
end
private
def ability_name
2020-07-28 23:09:34 +05:30
'update'
end
def update_params(args)
args.tap do |update_args|
# We need to rename `files` into `snippet_actions` because
# it's the expected key param
update_args[:snippet_actions] = update_args.delete(:files)&.map(&:to_h)
end
2020-01-01 13:55:28 +05:30
end
end
end
end