Sha256: 387b574730a36fa1f965bb267a84b6e7a34adb7d2cee9413dbc41dd8a81a3a17

Contents?: true

Size: 1020 Bytes

Versions: 15

Compression:

Stored size: 1020 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, context: nil, path: nil)
          path ||= context.path
          GraphQL::StaticValidation::Message.new(message, line: node.line, col: node.col, path: path)
        end
      end

      attr_reader :message, :line, :col, :path

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

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

      private

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphql-0.18.14 lib/graphql/static_validation/message.rb
graphql-0.18.13 lib/graphql/static_validation/message.rb
graphql-0.18.12 lib/graphql/static_validation/message.rb
graphql-0.18.11 lib/graphql/static_validation/message.rb
graphql-0.18.10 lib/graphql/static_validation/message.rb
graphql-0.18.9 lib/graphql/static_validation/message.rb
graphql-0.18.8 lib/graphql/static_validation/message.rb
graphql-0.18.7 lib/graphql/static_validation/message.rb
graphql-0.18.6 lib/graphql/static_validation/message.rb
graphql-0.18.5 lib/graphql/static_validation/message.rb
graphql-0.18.4 lib/graphql/static_validation/message.rb
graphql-0.18.3 lib/graphql/static_validation/message.rb
graphql-0.18.2 lib/graphql/static_validation/message.rb
graphql-0.18.1 lib/graphql/static_validation/message.rb
graphql-0.18.0 lib/graphql/static_validation/message.rb