Class: GraphQL::InternalRepresentation::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/internal_representation/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast_node: nil, return_type: nil, name: nil, definition_name: nil, definitions: {}, children: {}, spreads: [], directives: Set.new) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/graphql/internal_representation/node.rb', line 6

def initialize(ast_node: nil, return_type: nil, name: nil, definition_name: nil, definitions: {}, children: {}, spreads: [], directives: Set.new)
  # Make sure these are kept in sync with #dup
  @ast_node = ast_node
  @return_type = return_type
  @name = name
  @definition_name = definition_name
  @definitions = definitions
  @children = children
  @spreads = spreads
  @directives = directives
end

Instance Attribute Details

#ast_nodeGraphQL::Language::Nodes::AbstractNode (readonly)

Returns The AST node (or one of the nodes) where this was derived from.

Returns:



52
53
54
# File 'lib/graphql/internal_representation/node.rb', line 52

def ast_node
  @ast_node
end

#childrenArray<GraphQL::Query::Node> (readonly)

Returns:

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


58
59
60
# File 'lib/graphql/internal_representation/node.rb', line 58

def children
  @children
end

#definition_nameString (readonly)

Returns the name for this node’s definition (#name may be a field’s alias, this is always the name).

Returns:

  • (String)

    the name for this node’s definition (#name may be a field’s alias, this is always the name)



27
28
29
# File 'lib/graphql/internal_representation/node.rb', line 27

def definition_name
  @definition_name
end

#definitionsHash<GraphQL::BaseType => GraphQL::Field> (readonly)

A cache of type-field pairs for executing & analyzing this node

{

person(id: 1) {
  firstName # => defined type is person
}

} {

node(id: $nodeId) {
  ... on Nameable {
    firstName # => defined type is Nameable
  }
}

}

Examples:

On-type from previous return value

On-type from explicit type condition

Returns:



46
47
48
# File 'lib/graphql/internal_representation/node.rb', line 46

def definitions
  @definitions
end

#directivesSet<GraphQL::Language::Nodes::Directive> (readonly)

These are the compiled directives from fragment spreads, inline fragments, and the field itself



24
25
26
# File 'lib/graphql/internal_representation/node.rb', line 24

def directives
  @directives
end

#nameString (readonly)

Returns the name to use for the result in the response hash.

Returns:

  • (String)

    the name to use for the result in the response hash



49
50
51
# File 'lib/graphql/internal_representation/node.rb', line 49

def name
  @name
end

#return_typeGraphQL::BaseType (readonly)

Returns:



55
56
57
# File 'lib/graphql/internal_representation/node.rb', line 55

def return_type
  @return_type
end

#spreadsArray<GraphQL::Language::Nodes::FragmentSpreads> (readonly)

Note: by the time this gets out of the Rewrite phase, this will be empty – it’s emptied out when fragments are merged back in

Returns:

  • (Array<GraphQL::Language::Nodes::FragmentSpreads>)

    Fragment names that were spread in this node



20
21
22
# File 'lib/graphql/internal_representation/node.rb', line 20

def spreads
  @spreads
end

Instance Method Details

#inspect(indent = 0) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/graphql/internal_representation/node.rb', line 60

def inspect(indent = 0)
  own_indent = " " * indent
  self_inspect = "#{own_indent}<Node #{name} (#{definition_name}: {#{definitions.keys.join("|")}} -> #{return_type})>"
  if children.any?
    self_inspect << " {\n#{children.values.map { |n| n.inspect(indent + 2)}.join("\n")}\n#{own_indent}}"
  end
  self_inspect
end