class GraphQL::StaticValidation::Error

Generates GraphQL-compliant validation message.

Attributes

message[R]
nodes[R]
path[RW]

Public Class Methods

new(message, path: nil, nodes: []) click to toggle source
# File lib/graphql/static_validation/error.rb, line 19
def initialize(message, path: nil, nodes: [])
  @message = message
  @nodes = Array(nodes)
  @path = path
end

Public Instance Methods

to_h() click to toggle source

A hash representation of this Message

# 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

Private Instance Methods

locations() click to toggle source
# File lib/graphql/static_validation/error.rb, line 37
def locations
  nodes.map do |node|
    h = {"line" => node.line, "column" => node.col}
    h["filename"] = node.filename if node.filename
    h
  end
end