Sha256: a2326a4fd94002541edb93b75e7f1f8a4d6c0001fa4cf99fea9dcfb88b3bff31

Contents?: true

Size: 1022 Bytes

Versions: 13

Compression:

Stored size: 1022 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,
          "fields" => path,
        }
      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-1.2.4 lib/graphql/static_validation/message.rb
graphql-1.2.3 lib/graphql/static_validation/message.rb
graphql-1.2.2 lib/graphql/static_validation/message.rb
graphql-1.2.1 lib/graphql/static_validation/message.rb
graphql-1.2.0 lib/graphql/static_validation/message.rb
graphql-1.1.0 lib/graphql/static_validation/message.rb
graphql-1.0.0 lib/graphql/static_validation/message.rb
graphql-0.19.4 lib/graphql/static_validation/message.rb
graphql-0.19.3 lib/graphql/static_validation/message.rb
graphql-0.19.2 lib/graphql/static_validation/message.rb
graphql-0.19.1 lib/graphql/static_validation/message.rb
graphql-0.19.0 lib/graphql/static_validation/message.rb
graphql-0.18.15 lib/graphql/static_validation/message.rb