Class: GraphQL::Language::DefinitionSlice::DependencyVisitor

Inherits:
Visitor
  • Object
show all
Defined in:
lib/graphql/language/definition_slice.rb

Constant Summary

Constants inherited from Visitor

Visitor::DELETE_NODE, Visitor::SKIP

Instance Attribute Summary

Attributes inherited from Visitor

#result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from 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(doc, definitions, names) ⇒ DependencyVisitor

Returns a new instance of DependencyVisitor.



19
20
21
22
23
# File 'lib/graphql/language/definition_slice.rb', line 19

def initialize(doc, definitions, names)
  @names = names
  @definitions = definitions
  super(doc)
end

Class Method Details

.find_definition_dependencies(definitions, name, names) ⇒ Object



32
33
34
35
36
37
# File 'lib/graphql/language/definition_slice.rb', line 32

def self.find_definition_dependencies(definitions, name, names)
  names.add(name)
  visitor = self.new(definitions[name], definitions, names)
  visitor.visit
  nil
end

Instance Method Details

#on_fragment_spread(node, parent) ⇒ Object



25
26
27
28
29
30
# File 'lib/graphql/language/definition_slice.rb', line 25

def on_fragment_spread(node, parent)
  if fragment = @definitions[node.name]
    self.class.find_definition_dependencies(@definitions, fragment.name, @names)
  end
  super
end