Class: GraphQL::StaticValidation::BaseVisitor

Inherits:
Language::Visitor show all
Defined in:
lib/graphql/static_validation/base_visitor.rb

Direct Known Subclasses

InterpreterVisitor

Defined Under Namespace

Modules: ContextMethods

Constant Summary

Constants inherited from Language::Visitor

Language::Visitor::DELETE_NODE, Language::Visitor::SKIP

Instance Attribute Summary collapse

Attributes inherited from Language::Visitor

#result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Language::Visitor

#[], make_visit_methods, #on_argument_children, #on_document_children, #on_field_children, #on_fragment_definition_children, #on_operation_definition_children, #visit, #visit_directives, #visit_selections

Constructor Details

#initialize(document, context) ⇒ BaseVisitor

Returns a new instance of BaseVisitor.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/graphql/static_validation/base_visitor.rb', line 5

def initialize(document, context)
  @path = []
  @object_types = []
  @directives = []
  @field_definitions = []
  @argument_definitions = []
  @directive_definitions = []
  @context = context
  @schema = context.schema
  super(document)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#object_typesArray<GraphQL::ObjectType> (readonly)

Returns Types whose scope we’ve entered.

Returns:

  • (Array<GraphQL::ObjectType>)

    Types whose scope we’ve entered



20
21
22
# File 'lib/graphql/static_validation/base_visitor.rb', line 20

def object_types
  @object_types
end

Class Method Details

.including_rules(rules) ⇒ Class

Build a class to visit the AST and perform validation, or use a pre-built class if rules is ALL_RULES or empty.

Parameters:

  • rules (Array<Module, Class>)

Returns:

  • (Class)

    A class for validating rules during visitation



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/graphql/static_validation/base_visitor.rb', line 31

def self.including_rules(rules)
  if rules.empty?
    # It's not doing _anything?!?_
    BaseVisitor
  elsif rules == ALL_RULES
    InterpreterVisitor
  else
    visitor_class = Class.new(self) do
      include(GraphQL::StaticValidation::DefinitionDependencies)
    end

    rules.reverse_each do |r|
      # If it's a class, it gets attached later.
      if !r.is_a?(Class)
        visitor_class.include(r)
      end
    end

    visitor_class.include(ContextMethods)
    visitor_class
  end
end

Instance Method Details

#pathArray<String>

Returns The nesting of the current position in the AST.

Returns:

  • (Array<String>)

    The nesting of the current position in the AST



23
24
25
# File 'lib/graphql/static_validation/base_visitor.rb', line 23

def path
  @path.dup
end