Sha256: cfd60e7b2d8fe0598bf1e3b7d7495b79e2f5ab9cc54ac205330ce89ec25122a6

Contents?: true

Size: 885 Bytes

Versions: 13

Compression:

Stored size: 885 Bytes

Contents

module GraphQL
  module StaticValidation
    # Generates GraphQL-compliant validation message.
    # Only supports one "location", too bad :(
    class 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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-0.17.2 lib/graphql/static_validation/message.rb
graphql-0.17.1 lib/graphql/static_validation/message.rb
graphql-0.17.0 lib/graphql/static_validation/message.rb
graphql-0.16.1 lib/graphql/static_validation/message.rb
graphql-0.16.0 lib/graphql/static_validation/message.rb
graphql-0.15.3 lib/graphql/static_validation/message.rb
graphql-0.15.2 lib/graphql/static_validation/message.rb
graphql-0.14.2 lib/graphql/static_validation/message.rb
graphql-0.15.1 lib/graphql/static_validation/message.rb
graphql-0.15.0 lib/graphql/static_validation/message.rb
graphql-0.14.1 lib/graphql/static_validation/message.rb
graphql-0.14.0 lib/graphql/static_validation/message.rb
graphql-0.13.0 lib/graphql/static_validation/message.rb