Class: GraphQL::StaticValidation::ValidationContext

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/graphql/static_validation/validation_context.rb

Overview

The validation context gets passed to each validator.

It exposes a Language::Visitor where validators may add hooks. (Language::Visitor#visit is called in GraphQL::StaticValidation::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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, visitor_class) ⇒ ValidationContext

Returns a new instance of ValidationContext



22
23
24
25
26
27
28
# File 'lib/graphql/static_validation/validation_context.rb', line 22

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

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors



17
18
19
# File 'lib/graphql/static_validation/validation_context.rb', line 17

def errors
  @errors
end

#on_dependency_resolve_handlersObject (readonly)

Returns the value of attribute on_dependency_resolve_handlers



17
18
19
# File 'lib/graphql/static_validation/validation_context.rb', line 17

def on_dependency_resolve_handlers
  @on_dependency_resolve_handlers
end

#queryObject (readonly)

Returns the value of attribute query



17
18
19
# File 'lib/graphql/static_validation/validation_context.rb', line 17

def query
  @query
end

#visitorObject (readonly)

Returns the value of attribute visitor



17
18
19
# File 'lib/graphql/static_validation/validation_context.rb', line 17

def visitor
  @visitor
end

Instance Method Details

#on_dependency_resolve(&handler) ⇒ Object



34
35
36
# File 'lib/graphql/static_validation/validation_context.rb', line 34

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

#valid_literal?(ast_value, type) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/graphql/static_validation/validation_context.rb', line 38

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