Class: GraphQL::StaticValidation::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/static_validation/error.rb

Overview

Generates GraphQL-compliant validation message.

Defined Under Namespace

Modules: ErrorHelper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, path: nil, nodes: []) ⇒ Error

Returns a new instance of Error.



19
20
21
22
23
# File 'lib/graphql/static_validation/error.rb', line 19

def initialize(message, path: nil, nodes: [])
  @message = message
  @nodes = Array(nodes)
  @path = path
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



16
17
18
# File 'lib/graphql/static_validation/error.rb', line 16

def message
  @message
end

#nodesObject (readonly)

Returns the value of attribute nodes.



33
34
35
# File 'lib/graphql/static_validation/error.rb', line 33

def nodes
  @nodes
end

#pathObject

Returns the value of attribute path.



17
18
19
# File 'lib/graphql/static_validation/error.rb', line 17

def path
  @path
end

Instance Method Details

#to_hObject

A hash representation of this Message



26
27
28
29
30
31
# File 'lib/graphql/static_validation/error.rb', line 26

def to_h
  {
    "message" => message,
    "locations" => locations
  }.tap { |h| h["path"] = path unless path.nil? }
end