Sha256: a231dddbc56183c5de23dd4cc804d8919c77185d67d14f3423cb6024eed42fa6

Contents?: true

Size: 748 Bytes

Versions: 27

Compression:

Stored size: 748 Bytes

Contents

# Generates GraphQL-compliant validation message.
# Only supports one "location", too bad :(
class GraphQL::StaticValidation::Message
  # Convenience for validators
  module MessageHelper
    # Error `message` is located at `node`
    def message(message, node)
      GraphQL::StaticValidation::Message.new(message, line: node.line, col: node.col)
    end
  end
  attr_reader :message, :line, :col

  def initialize(message, line: nil, col: nil)
    @message = message
    @line = line
    @col = col
  end

  # A hash representation of this Message
  def to_h
    {
      "message" => message,
      "locations" => locations
    }
  end

  private

  def locations
    @line.nil? && @col.nil ? [] : [{"line" => @line, "column" => @col}]
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
graphql-0.12.1 lib/graphql/static_validation/message.rb
graphql-0.12.0 lib/graphql/static_validation/message.rb
graphql-0.11.1 lib/graphql/static_validation/message.rb
graphql-0.11.0 lib/graphql/static_validation/message.rb
graphql-0.10.9 lib/graphql/static_validation/message.rb
graphql-0.10.8 lib/graphql/static_validation/message.rb
graphql-0.10.7 lib/graphql/static_validation/message.rb
graphql-0.10.6 lib/graphql/static_validation/message.rb
graphql-0.10.5 lib/graphql/static_validation/message.rb
graphql-0.10.4 lib/graphql/static_validation/message.rb
graphql-0.10.3 lib/graphql/static_validation/message.rb
graphql-0.10.2 lib/graphql/static_validation/message.rb
graphql-0.10.1 lib/graphql/static_validation/message.rb
graphql-0.10.0 lib/graphql/static_validation/message.rb
graphql-0.9.5 lib/graphql/static_validation/message.rb
graphql-0.9.4 lib/graphql/static_validation/message.rb
graphql-0.9.3 lib/graphql/static_validation/message.rb
graphql-0.9.2 lib/graphql/static_validation/message.rb
graphql-0.8.1 lib/graphql/static_validation/message.rb
graphql-0.8.0 lib/graphql/static_validation/message.rb