Sha256: ddf61aa584d5f47fc92d5a748f87a4e9214c6b447cedc6c9cba982ee08201d2f

Contents?: true

Size: 1.46 KB

Versions: 35

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    # The validation context gets passed to each validator.
    #
    # It exposes a {GraphQL::Language::Visitor} where validators may add hooks. ({Language::Visitor#visit} is called in {Validator#validate})
    #
    # It provides access to the schema & fragments which validators may read from.
    #
    # It holds a list of errors which each validator may add to.
    #
    # It also provides limited access to the {TypeStack} instance,
    # which tracks state as you climb in and out of different fields.
    class ValidationContext
      extend Forwardable

      attr_reader :query, :errors, :visitor,
        :on_dependency_resolve_handlers

      def_delegators :@query, :schema, :document, :fragments, :operations, :warden

      def initialize(query, visitor_class)
        @query = query
        @literal_validator = LiteralValidator.new(context: query.context)
        @errors = []
        @on_dependency_resolve_handlers = []
        @visitor = visitor_class.new(document, self)
      end

      def_delegators :@visitor,
        :path, :type_definition, :field_definition, :argument_definition,
        :parent_type_definition, :directive_definition, :object_types, :dependencies

      def on_dependency_resolve(&handler)
        @on_dependency_resolve_handlers << handler
      end

      def valid_literal?(ast_value, type)
        @literal_validator.validate(ast_value, type)
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
graphql-1.9.21 lib/graphql/static_validation/validation_context.rb
graphql-1.9.20 lib/graphql/static_validation/validation_context.rb
graphql-1.10.4 lib/graphql/static_validation/validation_context.rb
graphql-1.10.3 lib/graphql/static_validation/validation_context.rb
graphql-1.10.2 lib/graphql/static_validation/validation_context.rb
graphql-1.9.19 lib/graphql/static_validation/validation_context.rb
graphql-1.10.1 lib/graphql/static_validation/validation_context.rb
graphql-1.10.0 lib/graphql/static_validation/validation_context.rb
graphql-1.10.0.pre4 lib/graphql/static_validation/validation_context.rb
graphql-1.9.18 lib/graphql/static_validation/validation_context.rb
graphql-1.10.0.pre3 lib/graphql/static_validation/validation_context.rb
graphql-1.9.17 lib/graphql/static_validation/validation_context.rb
graphql-1.10.0.pre2 lib/graphql/static_validation/validation_context.rb
graphql-1.9.16 lib/graphql/static_validation/validation_context.rb
graphql-1.9.15 lib/graphql/static_validation/validation_context.rb
graphql-1.9.14 lib/graphql/static_validation/validation_context.rb
graphql-1.10.0.pre1 lib/graphql/static_validation/validation_context.rb
graphql-1.9.13 lib/graphql/static_validation/validation_context.rb
graphql-1.9.12 lib/graphql/static_validation/validation_context.rb
graphql-1.9.11 lib/graphql/static_validation/validation_context.rb