Class: GraphqlRails::ValidationError

Inherits:
ExecutionError
  • Object
show all
Defined in:
lib/graphql_rails/errors/validation_error.rb

Overview

GraphQL error that is raised when invalid data is given

Constant Summary collapse

BASE_FIELD_NAME =
'base'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ExecutionError

#extra_graphql_data

Constructor Details

#initialize(short_message, field) ⇒ ValidationError

Returns a new instance of ValidationError.



10
11
12
13
14
# File 'lib/graphql_rails/errors/validation_error.rb', line 10

def initialize(short_message, field)
  super([humanized_field(field), short_message].compact.join(' '))
  @short_message = short_message
  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



8
9
10
# File 'lib/graphql_rails/errors/validation_error.rb', line 8

def field
  @field
end

#short_messageObject (readonly)

Returns the value of attribute short_message.



8
9
10
# File 'lib/graphql_rails/errors/validation_error.rb', line 8

def short_message
  @short_message
end

Instance Method Details

#to_hObject



20
21
22
# File 'lib/graphql_rails/errors/validation_error.rb', line 20

def to_h
  super.merge('field' => field, 'short_message' => short_message)
end

#typeObject



16
17
18
# File 'lib/graphql_rails/errors/validation_error.rb', line 16

def type
  'validation_error'
end