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

: (String? message, ?path: Array[String | Integer]?, ?nodes: GraphQL::Language::Nodes::AbstractNode | Array) -> void



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

def initialize(message, path: nil, nodes: [])
  @message = message #: String?
  @nodes = Array(nodes) #: Array[GraphQL::Language::Nodes::AbstractNode]
  @path = path #: Array[String | Integer]?
end

Instance Attribute Details

#message ⇒ Object (readonly)

: String?



23
24
25
# File 'lib/graphql/static_validation/error.rb', line 23

def message
  @message
end

#nodes ⇒ Object (readonly)

: Array



44
45
46
# File 'lib/graphql/static_validation/error.rb', line 44

def nodes
  @nodes
end

#path ⇒ Object

: Array[String | Integer]?



25
26
27
# File 'lib/graphql/static_validation/error.rb', line 25

def path
  @path
end

Instance Method Details

#to_h ⇒ Object

A hash representation of this Message : -> Hash[String, untyped]



36
37
38
39
40
41
# File 'lib/graphql/static_validation/error.rb', line 36

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