2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
class BaseMutation < GraphQL::Schema::RelayClassicMutation
|
2019-09-30 21:07:59 +05:30
|
|
|
prepend Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
prepend Gitlab::Graphql::CopyFieldDescription
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
ERROR_MESSAGE = 'You cannot perform write operations on a read-only instance'
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
field :errors, [GraphQL::STRING_TYPE],
|
|
|
|
null: false,
|
2020-05-24 23:13:21 +05:30
|
|
|
description: "Errors encountered during execution of the mutation."
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
def current_user
|
|
|
|
context[:current_user]
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
# Returns Array of errors on an ActiveRecord object
|
|
|
|
def errors_on_object(record)
|
|
|
|
record.errors.full_messages
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
def ready?(**args)
|
|
|
|
if Gitlab::Database.read_only?
|
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable, ERROR_MESSAGE
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
end
|