2018-07-10 10:19:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
class BaseMutation < GraphQL::Schema::RelayClassicMutation
|
2019-07-01 00:44:51 -04:00
|
|
|
prepend Gitlab::Graphql::Authorize::AuthorizeResource
|
2019-06-21 00:45:27 -04:00
|
|
|
prepend Gitlab::Graphql::CopyFieldDescription
|
|
|
|
|
2019-09-20 14:06:35 -04:00
|
|
|
ERROR_MESSAGE = 'You cannot perform write operations on a read-only instance'
|
|
|
|
|
2020-07-07 08:09:16 -04:00
|
|
|
field_class ::Types::BaseField
|
|
|
|
|
2018-07-10 10:19:45 -04:00
|
|
|
field :errors, [GraphQL::STRING_TYPE],
|
|
|
|
null: false,
|
2020-05-20 08:07:52 -04:00
|
|
|
description: 'Errors encountered during execution of the mutation.'
|
2018-07-10 10:19:45 -04:00
|
|
|
|
|
|
|
def current_user
|
|
|
|
context[:current_user]
|
|
|
|
end
|
2019-06-21 00:45:27 -04:00
|
|
|
|
2020-08-20 08:10:27 -04:00
|
|
|
def api_user?
|
|
|
|
context[:is_sessionless_user]
|
|
|
|
end
|
|
|
|
|
2019-06-21 00:45:27 -04:00
|
|
|
# Returns Array of errors on an ActiveRecord object
|
|
|
|
def errors_on_object(record)
|
|
|
|
record.errors.full_messages
|
|
|
|
end
|
2019-09-20 14:06:35 -04:00
|
|
|
|
|
|
|
def ready?(**args)
|
|
|
|
if Gitlab::Database.read_only?
|
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable, ERROR_MESSAGE
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2018-07-10 10:19:45 -04:00
|
|
|
end
|
|
|
|
end
|