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, OperationDefinitionStrategy Classes: EnterWithStrategy, LeaveWithStrategy

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

Returns a new instance of TypeStack.

Parameters:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/graphql/static_validation/type_stack.rb', line 38

def initialize(schema, visitor)
  @schema = schema
  @object_types = []
  @field_definitions = []
  @directive_definitions = []
  @argument_definitions = []
  @path = []

  PUSH_STRATEGIES.each do |node_class, strategy|
    visitor[node_class].enter << EnterWithStrategy.new(self, strategy)
    visitor[node_class].leave << LeaveWithStrategy.new(self, strategy)
  end
end

Instance Attribute Details

#argument_definitionsArray<GraphQL::Node::Argument> (readonly)

Returns arguments which have been entered.

Returns:

  • (Array<GraphQL::Node::Argument>)

    arguments which have been entered



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

def argument_definitions
  @argument_definitions
end

#directive_definitionsArray<GraphQL::Node::Directive> (readonly)

Directives are pushed on, then popped off while traversing the tree

Returns:

  • (Array<GraphQL::Node::Directive>)

    directives which have been entered



28
29
30
# File 'lib/graphql/static_validation/type_stack.rb', line 28

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.

Returns:

  • (Array<GraphQL::Field>)

    fields which have been entered



24
25
26
# File 'lib/graphql/static_validation/type_stack.rb', line 24

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.

Returns:

  • (Array<GraphQL::ObjectType, GraphQL::Union, GraphQL::Interface>)


19
20
21
# File 'lib/graphql/static_validation/type_stack.rb', line 19

def object_types
  @object_types
end

#pathArray<String> (readonly)

Returns fields which have been entered (by their AST name).

Returns:

  • (Array<String>)

    fields which have been entered (by their AST name)



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

def path
  @path
end

#schemaGraphQL::Schema (readonly)

Returns the schema whose types are present in this document.

Returns:

  • (GraphQL::Schema)

    the schema whose types are present in this document



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

def schema
  @schema
end