Class: GraphQL::StaticValidation::BaseVisitor

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

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_method, #on_abstract_node, #visit, #visit_node

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


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

def context
  @context
end

#object_typesArray<GraphQL::ObjectType> (readonly)

Returns Types whose scope we've entered.

Returns:


25
26
27
# File 'lib/graphql/static_validation/base_visitor.rb', line 25

def object_types
  @object_types
end

Class Method Details

.including_rules(rules, rewrite: true) ⇒ 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>)
  • rewrite (Boolean) (defaults to: true)

    if false, don't include rewrite

Returns:

  • (Class)

    A class for validating rules during visitation


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/graphql/static_validation/base_visitor.rb', line 37

def self.including_rules(rules, rewrite: true)
  if rules.empty?
    if rewrite
      NoValidateVisitor
    else
      # It's not doing _anything?!?_
      BaseVisitor
    end
  elsif rules == ALL_RULES
    if rewrite
      DefaultVisitor
    else
      InterpreterVisitor
    end
  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

    if rewrite
      visitor_class.include(GraphQL::InternalRepresentation::Rewrite)
    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


28
29
30
# File 'lib/graphql/static_validation/base_visitor.rb', line 28

def path
  @path.dup
end

#rewrite_documentObject

This will be overwritten by InternalRepresentation::Rewrite if it's included


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

def rewrite_document
  nil
end