Class: GraphQL::DSL::Node Abstract

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

Overview

This class is abstract.

Base class for all GraphQL DSL nodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, &block) ⇒ Node

Create node

Parameters:

  • name (String, Symbol, nil) (defaults to: nil)

    node name

  • block (Proc)

    declare DSL for sub-nodes



20
21
22
23
24
25
# File 'lib/graphql/dsl/nodes/node.rb', line 20

def initialize(name = nil, &block)
  @__name = name
  @__nodes = []

  instance_eval(&block) if block
end

Instance Attribute Details

#__nameString, ... (readonly)

Returns node name.

Returns:

  • (String, Symbol, nil)

    node name



10
11
12
# File 'lib/graphql/dsl/nodes/node.rb', line 10

def __name
  @__name
end

#__nodesArray<Node> (readonly)

Returns list of sub-nodes.

Returns:

  • (Array<Node>)

    list of sub-nodes



13
14
15
# File 'lib/graphql/dsl/nodes/node.rb', line 13

def __nodes
  @__nodes
end

Instance Method Details

#to_gql(level = 0, formatter = Formatter.new) ⇒ String

Generate GraphQL query

Parameters:

  • level (Integer) (defaults to: 0)

    indent level

  • formatter (Formatter) (defaults to: Formatter.new)

    GraphQL query formatter

Returns:

  • (String)

    GraphQL query string



34
35
36
# File 'lib/graphql/dsl/nodes/node.rb', line 34

def to_gql(level = 0, formatter = Formatter.new)
  formatter.format_node(self, level)
end