module GraphQL::StaticValidation::BaseVisitor::ContextMethods
Constants
- INLINE_FRAGMENT_NO_TYPE
Public Class Methods
(GraphQL::Language::Nodes::Document document, GraphQL::StaticValidation::ValidationContext context) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 82 def initialize(document, context) super @path = path_parts #: Array[String | Integer] @path_depth = path_depth #: Integer @types = types #: GraphQL::Schema::Visibility::Profile | GraphQL::Schema::Warden::VisibilityProfile @inline_fragment_paths = inline_fragment_paths #: Hash[String, String] @field_unwrapped_types = field_unwrapped_types #: Hash[GraphQL::Schema::Field, GraphQL::Schema::Member::type_definition] @child_positions = child_positions_by_parent #: Hash[GraphQL::Language::Nodes::AbstractNode, Hash[GraphQL::Language::Nodes::AbstractNode, Integer]] end
BaseVisitor#initialize sets these. Theyβre re-assigned here so Sorbet knows their types in this module, because the hooks below use them directly instead of calling the readers on every node.
Calls superclass method
Public Instance Methods
# File lib/graphql/static_validation/base_visitor.rb, line 296 def argument_definition # Return the parent argument definition (not the current one). @parent_argument_definition end
Returns
-
GraphQL::Argument, nilβ The most-recently-entered GraphQL::Argument, if currently inside one
(GraphQL::Language::Nodes::AbstractNode parent) → Hash[GraphQL::Language::Nodes::AbstractNode, Integer]
Source
# File lib/graphql/static_validation/base_visitor.rb, line 237 def child_positions(parent) @child_positions[parent] ||= begin positions = {}.compare_by_identity #: Hash[GraphQL::Language::Nodes::AbstractNode, Integer] parent.children.each_with_index { |child, index| positions[child] ||= index } positions end end
() → singleton(GraphQL::Schema::Directive)?
Source
# File lib/graphql/static_validation/base_visitor.rb, line 285 def directive_definition @current_directive_definition end
Returns
-
GraphQL::Directive, nilβ The most-recently-entered GraphQL::Directive, if currently inside one
# File lib/graphql/static_validation/base_visitor.rb, line 274 def field_definition @current_field_definition end
Returns
-
GraphQL::Field, nilβ The most-recently-entered GraphQL::Field, if currently inside one
(GraphQL::Language::Nodes::Argument node, GraphQL::Language::Nodes::AbstractNode? parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 184 def on_argument(node, parent) argument_defn = if (arg = @current_argument_definition) arg_type = arg.type.unwrap if arg_type.kind.input_object? @types.argument(arg_type, node.name) else nil end elsif (directive_defn = @current_directive_definition) @types.argument(directive_defn, node.name) elsif (field_defn = @current_field_definition) @types.argument(field_defn, node.name) else nil end prev_parent = @parent_argument_definition @parent_argument_definition = @current_argument_definition #: GraphQL::Schema::Argument? @current_argument_definition = argument_defn #: GraphQL::Schema::Argument? path_depth = @path_depth @path[path_depth] = node.name @path_depth = path_depth + 1 super @current_argument_definition = @parent_argument_definition @parent_argument_definition = prev_parent @path_depth = path_depth @child_positions.delete(node) end
Calls superclass method
(GraphQL::Language::Nodes::Directive node, GraphQL::Language::Nodes::AbstractNode? parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 175 def on_directive(node, parent) directive_defn = context.schema_directives[node.name] prev_directive_definition = @current_directive_definition @current_directive_definition = directive_defn #: singleton(GraphQL::Schema::Directive)? super @current_directive_definition = prev_directive_definition end
Calls superclass method
(GraphQL::Language::Nodes::Field node, GraphQL::Language::Nodes::AbstractNode? parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 152 def on_field(node, parent) parent_type = @current_object_type field_definition = @types.field(parent_type, node.name) prev_field_definition = @current_field_definition @current_field_definition = field_definition #: GraphQL::Schema::Field? prev_parent_ot = @parent_object_type @parent_object_type = @current_object_type if field_definition @current_object_type = @field_unwrapped_types[field_definition] ||= field_definition.type.unwrap else @current_object_type = nil end path_depth = @path_depth @path[path_depth] = node.alias || node.name @path_depth = path_depth + 1 super @current_field_definition = prev_field_definition @current_object_type = @parent_object_type @parent_object_type = prev_parent_ot @path_depth = path_depth end
Calls superclass method
(GraphQL::Language::Nodes::FragmentDefinition node, GraphQL::Language::Nodes::AbstractNode? parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 108 def on_fragment_definition(node, parent) # The type is always present when parsed, but may be missing on a hand-built node: fragment_type = node.type #: GraphQL::Language::Nodes::TypeName? object_type = if fragment_type @types.type(fragment_type.name) else @current_object_type end prev_parent_ot = @parent_object_type @parent_object_type = @current_object_type @current_object_type = object_type path_depth = @path_depth @path[path_depth] = "fragment #{node.name}" @path_depth = path_depth + 1 super @current_object_type = @parent_object_type @parent_object_type = prev_parent_ot @path_depth = path_depth end
Calls superclass method
(GraphQL::Language::Nodes::FragmentSpread node, GraphQL::Language::Nodes::AbstractNode? parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 214 def on_fragment_spread(node, parent) path_depth = @path_depth @path[path_depth] = "... #{node.name}" @path_depth = path_depth + 1 super @path_depth = path_depth end
Calls superclass method
(GraphQL::Language::Nodes::InlineFragment node, GraphQL::Language::Nodes::AbstractNode? parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 131 def on_inline_fragment(node, parent) path_depth = @path_depth if (node_type = node.type) object_type = @types.type(node_type.name) @path[path_depth] = @inline_fragment_paths[node_type.name] ||= -"... on #{node_type.to_query_string}" @path_depth = path_depth + 1 else object_type = @current_object_type @path[path_depth] = INLINE_FRAGMENT_NO_TYPE @path_depth = path_depth + 1 end prev_parent_ot = @parent_object_type @parent_object_type = @current_object_type @current_object_type = object_type super @current_object_type = @parent_object_type @parent_object_type = prev_parent_ot @path_depth = path_depth end
Calls superclass method
(GraphQL::Language::Nodes::InputObject node, GraphQL::Language::Nodes::AbstractNode parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 223 def on_input_object(node, parent) arg_defn = @current_argument_definition if arg_defn && arg_defn.type.list? path_depth = @path_depth @path[path_depth] = child_positions(parent)[node] #: as !nil @path_depth = path_depth + 1 super @path_depth = path_depth else super end end
Calls superclass method
(GraphQL::Language::Nodes::OperationDefinition node, GraphQL::Language::Nodes::AbstractNode? parent) → void
Source
# File lib/graphql/static_validation/base_visitor.rb, line 93 def on_operation_definition(node, parent) object_type = schema.root_type_for_operation(node.operation_type) prev_parent_ot = @parent_object_type @parent_object_type = @current_object_type #: GraphQL::Schema::Member::type_definition? @current_object_type = object_type #: GraphQL::Schema::Member::type_definition? path_depth = @path_depth @path[path_depth] = "#{node.operation_type}#{node.name ? " #{node.name}" : ""}" @path_depth = path_depth + 1 super @current_object_type = @parent_object_type @parent_object_type = prev_parent_ot @path_depth = path_depth end
Calls superclass method
() → GraphQL::Schema::Member::type_definition?
Source
# File lib/graphql/static_validation/base_visitor.rb, line 263 def parent_type_definition @parent_object_type end
Returns
-
GraphQL::BaseTypeβ The type which the current type came from
() → GraphQL::Schema::Member::type_definition?
Source
# File lib/graphql/static_validation/base_visitor.rb, line 252 def type_definition @current_object_type end
Returns
-
GraphQL::BaseTypeβ The current object type