Class: Mutations::BaseMutation

Inherits:
GraphQL::Schema::RelayClassicMutation
  • Object
show all
Defined in:
app/graphql/mutations/base_mutation.rb

Constant Summary collapse

ERROR_MESSAGE =
'You cannot perform write operations on a read-only instance'

Instance Method Summary collapse

Instance Method Details

#api_user?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'app/graphql/mutations/base_mutation.rb', line 20

def api_user?
  context[:is_sessionless_user]
end

#current_userObject


16
17
18
# File 'app/graphql/mutations/base_mutation.rb', line 16

def current_user
  context[:current_user]
end

#errors_on_object(record) ⇒ Object

Returns Array of errors on an ActiveRecord object


25
26
27
# File 'app/graphql/mutations/base_mutation.rb', line 25

def errors_on_object(record)
  record.errors.full_messages
end

#ready?(**args) ⇒ Boolean

Returns:

  • (Boolean)

29
30
31
32
33
34
35
# File 'app/graphql/mutations/base_mutation.rb', line 29

def ready?(**args)
  if Gitlab::Database.read_only?
    raise Gitlab::Graphql::Errors::ResourceNotAvailable, ERROR_MESSAGE
  else
    true
  end
end