module GraphQL::StaticValidation::DefinitionDependencies
Track fragment dependencies for operations and expose the fragment definitions which are used by a given operation
Attributes
Public Class Methods
Source
# File lib/graphql/static_validation/definition_dependencies.rb, line 13 def initialize(*) super @defdep_node_paths = {} # { name => [node, ...] } pairs for fragments (although duplicate-named fragments are _invalid_, they are _possible_) @defdep_fragment_definitions = Hash.new{ |h, k| h[k] = [] } # This tracks dependencies from fragment to Node where it was used # { fragment_definition_name => [dependent_node, dependent_node]} @defdep_dependent_definitions = Hash.new { |h, k| h[k] = Set.new } # First-level usages of spreads within definitions # (When a key has an empty list as its value, # we can resolve that key's dependents) # { definition_node => [node, node ...] } @defdep_immediate_dependencies = Hash.new { |h, k| h[k] = Set.new } # When we encounter a spread, # this node is the one who depends on it @defdep_current_parent = nil end
Calls superclass method
Public Instance Methods
# File lib/graphql/static_validation/definition_dependencies.rb, line 78 def dependency_map(&block) @dependency_map ||= resolve_dependencies(&block) end
Source
# File lib/graphql/static_validation/definition_dependencies.rb, line 35 def on_document(node, parent) node.definitions.each do |definition| if definition.is_a? GraphQL::Language::Nodes::FragmentDefinition @defdep_fragment_definitions[definition.name] << definition end end super @dependencies = dependency_map { |defn, spreads, frag| context.on_dependency_resolve_handlers.each { |h| h.call(defn, spreads, frag) } } end
Calls superclass method
# File lib/graphql/static_validation/definition_dependencies.rb, line 54 def on_fragment_definition(node, parent) @defdep_node_paths[node] = NodeWithPath.new(node, context.path) @defdep_current_parent = node super @defdep_current_parent = nil end
Calls superclass method
# File lib/graphql/static_validation/definition_dependencies.rb, line 61 def on_fragment_spread(node, parent) @defdep_node_paths[node] = NodeWithPath.new(node, context.path) # Track both sides of the dependency @defdep_dependent_definitions[node.name] << @defdep_current_parent @defdep_immediate_dependencies[@defdep_current_parent] << node super end
Calls superclass method
# File lib/graphql/static_validation/definition_dependencies.rb, line 47 def on_operation_definition(node, prev_node) @defdep_node_paths[node.name] = NodeWithPath.new(node, context.path) @defdep_current_parent = node super @defdep_current_parent = nil end
Calls superclass method