Class: GQL::Connection

Inherits:
Node
  • Object
show all
Defined in:
lib/gql/connection.rb

Instance Attribute Summary

Attributes inherited from Node

#__context, #__target

Instance Method Summary collapse

Methods inherited from Node

#__raw_value, #__value, call, cursor, field, fields, method_missing, #method_missing

Constructor Details

#initialize(node_class, *args) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
9
# File 'lib/gql/connection.rb', line 5

def initialize(node_class, *args)
  super(*args)

  @node_class = node_class
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GQL::Node

Instance Method Details

#edgesObject



17
18
19
20
21
22
23
24
# File 'lib/gql/connection.rb', line 17

def edges
  raise Errors::InvalidNodeClass.new(@node_class, Node) unless @node_class < Node

  items.map do |item|
    node = @node_class.new(edges_ast_node, item, @variables, __context)
    node.__value
  end
end

#edges_ast_nodeObject



13
14
15
# File 'lib/gql/connection.rb', line 13

def edges_ast_node
  @edges_ast_node ||= @ast_node.fields.find { |f| f.name == :edges }
end