Class: GraphQL::StaticValidation::TypeStack
- Inherits:
-
Object
- Object
- GraphQL::StaticValidation::TypeStack
- Defined in:
- lib/graphql/static_validation/type_stack.rb
Overview
-
Ride along with ‘GraphQL::Language::Visitor`
-
Track type info, expose it to validators
Defined Under Namespace
Classes: ArgumentStrategy, DirectiveStrategy, FieldStrategy, FragmentDefinitionStrategy, FragmentSpreadStrategy, FragmentWithTypeStrategy, InlineFragmentStrategy, NullStrategy, OperationDefinitionStrategy
Constant Summary collapse
- TYPE_INFERRENCE_ROOTS =
These are jumping-off points for infering types down the tree
[ GraphQL::Language::Nodes::OperationDefinition, GraphQL::Language::Nodes::FragmentDefinition, ]
Instance Attribute Summary collapse
-
#argument_definitions ⇒ Array<GraphQL::Node::Argument>
readonly
Arguments which have been entered.
-
#directive_definitions ⇒ Array<GraphQL::Node::Directive>
readonly
Directives are pushed on, then popped off while traversing the tree.
-
#field_definitions ⇒ Array<GraphQL::Field>
readonly
When it enters a field, it’s pushed on this stack (useful for nested fields, args).
-
#object_types ⇒ Array<GraphQL::ObjectType, GraphQL::Union, GraphQL::Interface>
readonly
When it enters an object (starting with query or mutation root), it’s pushed on this stack.
-
#path ⇒ Array<String>
readonly
Fields which have been entered (by their AST name).
-
#schema ⇒ GraphQL::Schema
readonly
The schema whose types are present in this document.
Instance Method Summary collapse
-
#initialize(schema, visitor) ⇒ TypeStack
constructor
A new instance of TypeStack.
Constructor Details
#initialize(schema, visitor) ⇒ TypeStack
Returns a new instance of TypeStack.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/graphql/static_validation/type_stack.rb', line 37 def initialize(schema, visitor) @schema = schema @object_types = [] @field_definitions = [] @directive_definitions = [] @argument_definitions = [] @path = [] visitor.enter << -> (node, parent) { PUSH_STRATEGIES[node.class].push(self, node) } visitor.leave << -> (node, parent) { PUSH_STRATEGIES[node.class].pop(self, node) } end |
Instance Attribute Details
#argument_definitions ⇒ Array<GraphQL::Node::Argument> (readonly)
Returns arguments which have been entered.
30 31 32 |
# File 'lib/graphql/static_validation/type_stack.rb', line 30 def argument_definitions @argument_definitions end |
#directive_definitions ⇒ Array<GraphQL::Node::Directive> (readonly)
Directives are pushed on, then popped off while traversing the tree
27 28 29 |
# File 'lib/graphql/static_validation/type_stack.rb', line 27 def directive_definitions @directive_definitions end |
#field_definitions ⇒ Array<GraphQL::Field> (readonly)
When it enters a field, it’s pushed on this stack (useful for nested fields, args). When it exits, it’s popped off.
23 24 25 |
# File 'lib/graphql/static_validation/type_stack.rb', line 23 def field_definitions @field_definitions end |
#object_types ⇒ Array<GraphQL::ObjectType, GraphQL::Union, GraphQL::Interface> (readonly)
When it enters an object (starting with query or mutation root), it’s pushed on this stack. When it exits, it’s popped off.
18 19 20 |
# File 'lib/graphql/static_validation/type_stack.rb', line 18 def object_types @object_types end |
#path ⇒ Array<String> (readonly)
Returns fields which have been entered (by their AST name).
33 34 35 |
# File 'lib/graphql/static_validation/type_stack.rb', line 33 def path @path end |
#schema ⇒ GraphQL::Schema (readonly)
Returns the schema whose types are present in this document.
13 14 15 |
# File 'lib/graphql/static_validation/type_stack.rb', line 13 def schema @schema end |