Sha256: 790ee95bfb5095573701086c81a017c49e36aa5f56796fe65665ba9fcab1fb6f

Contents?: true

Size: 973 Bytes

Versions: 61

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    # Generates GraphQL-compliant validation message.
    class Message
      # Convenience for validators
      module MessageHelper
        # Error `message` is located at `node`
        def message(message, nodes, context: nil, path: nil)
          path ||= context.path
          nodes = Array(nodes)
          GraphQL::StaticValidation::Message.new(message, nodes: nodes, path: path)
        end
      end

      attr_reader :message, :path

      def initialize(message, path: [], nodes: [])
        @message = message
        @nodes = nodes
        @path = path
      end

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

      private

      def locations
        @nodes.map{|node| {"line" => node.line, "column" => node.col}}
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
graphql-1.8.4 lib/graphql/static_validation/message.rb
graphql-1.8.3 lib/graphql/static_validation/message.rb
graphql-1.8.2 lib/graphql/static_validation/message.rb
graphql-1.8.1 lib/graphql/static_validation/message.rb
graphql-1.8.0 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre11 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre10 lib/graphql/static_validation/message.rb
graphql-1.7.14 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre9 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre8 lib/graphql/static_validation/message.rb
graphql-1.7.13 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre7 lib/graphql/static_validation/message.rb
graphql-1.7.12 lib/graphql/static_validation/message.rb
graphql-1.7.11 lib/graphql/static_validation/message.rb
graphql-1.7.10 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre6 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre5 lib/graphql/static_validation/message.rb
graphql-1.7.9 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre4 lib/graphql/static_validation/message.rb
graphql-1.8.0.pre3 lib/graphql/static_validation/message.rb