Class: GQLi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gqli/base.rb

Overview

Base class for GraphQL type wrappers

Direct Known Subclasses

Fragment, Mutation, Node, Query, Subscription

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, depth = 0, &block) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/gqli/base.rb', line 10

def initialize(name = nil, depth = 0, &block)
  @__name = name
  @__depth = depth
  @__nodes = []
  instance_eval(&block) unless block.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



60
61
62
# File 'lib/gqli/base.rb', line 60

def method_missing(name, *args, &block)
  __node(name.to_s, __params_from_args(args), &block)
end

Instance Attribute Details

#__depthObject (readonly)

Returns the value of attribute __depth.



8
9
10
# File 'lib/gqli/base.rb', line 8

def __depth
  @__depth
end

#__nameObject (readonly)

Returns the value of attribute __name.



8
9
10
# File 'lib/gqli/base.rb', line 8

def __name
  @__name
end

#__nodesObject (readonly)

Returns the value of attribute __nodes.



8
9
10
# File 'lib/gqli/base.rb', line 8

def __nodes
  @__nodes
end

Instance Method Details

#___(fragment) ⇒ Object

Inlines fragment nodes into current node



18
19
20
# File 'lib/gqli/base.rb', line 18

def ___(fragment)
  @__nodes += __clone_nodes(fragment)
end

#__enum(value) ⇒ Object

Creates an EnumType value



34
35
36
# File 'lib/gqli/base.rb', line 34

def __enum(value)
  EnumValue.new(value)
end

#__node(name, params = {}, &block) ⇒ Object

Adds children node into current node



28
29
30
31
# File 'lib/gqli/base.rb', line 28

def __node(name, params = {}, &block)
  require_relative './node'
  @__nodes << Node.new(name, params, __depth + 1, &block)
end

#__on(type_name, &block) ⇒ Object

Adds type match node



23
24
25
# File 'lib/gqli/base.rb', line 23

def __on(type_name, &block)
  __node("... on #{type_name}", {}, &block)
end