class GraphQL::StaticValidation::ValidationContext

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

def argument_definition

Returns:
  • (GraphQL::Argument, nil) - The most-recently-entered GraphQL::Argument, if currently inside one
def argument_definition
  # Don't get the _last_ one because that's the current one.
  # Get the second-to-last one, which is the parent of the current one.
  @type_stack.argument_definitions[-2]
end

def directive_definition

Returns:
  • (GraphQL::Directive, nil) - The most-recently-entered GraphQL::Directive, if currently inside one
def directive_definition
  @type_stack.directive_definitions.last
end

def field_definition

Returns:
  • (GraphQL::Field, nil) - The most-recently-entered GraphQL::Field, if currently inside one
def field_definition
  @type_stack.field_definitions.last
end

def initialize(query)

def initialize(query)
  @query = query
  @schema = query.schema
  @document = query.document
  @fragments = {}
  @operations = {}
  @warden = query.warden
  document.definitions.each do |definition|
    case definition
    when GraphQL::Language::Nodes::FragmentDefinition
      @fragments[definition.name] = definition
    when GraphQL::Language::Nodes::OperationDefinition
      @operations[definition.name] = definition
    end
  end
  @errors = []
  @visitor = GraphQL::Language::Visitor.new(document)
  @type_stack = GraphQL::StaticValidation::TypeStack.new(schema, visitor)
end

def object_types

def object_types
  @type_stack.object_types
end

def parent_type_definition

Returns:
  • (GraphQL::BaseType) - The type which the current type came from
def parent_type_definition
  object_types[-2]
end

def path

Returns:
  • (Array) - Field names to get to the current field
def path
  @type_stack.path.dup
end

def type_definition

Returns:
  • (GraphQL::BaseType) - The current object type
def type_definition
  object_types.last
end

def valid_literal?(ast_value, type)

def valid_literal?(ast_value, type)
  @literal_validator ||= LiteralValidator.new(warden: @warden)
  @literal_validator.validate(ast_value, type)
end