Class: GraphQL::StaticValidation::TypeStack

Inherits:
Object
  • Object
show all
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

Modules: 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

Instance Method Summary collapse

Constructor Details

#initialize(schema, visitor) ⇒ 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_definitionsArray<GraphQL::Node::Argument> (readonly)


30
31
32
# File 'lib/graphql/static_validation/type_stack.rb', line 30

def argument_definitions
  @argument_definitions
end

#directive_definitionsArray<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_definitionsArray<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_typesArray<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

#pathArray<String> (readonly)


33
34
35
# File 'lib/graphql/static_validation/type_stack.rb', line 33

def path
  @path
end

#schemaGraphQL::Schema (readonly)


13
14
15
# File 'lib/graphql/static_validation/type_stack.rb', line 13

def schema
  @schema
end