Class: GraphQL::Relay::Node

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/graphql/relay/node.rb

Overview

To get a ‘NodeField` and `NodeInterface`, define an object that responds to:

- object_from_id
- type_from_object

and pass it to ‘Node.create`

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_missing(method_name, *args, &block) ⇒ Object

Allows you to call methods on the class



14
15
16
17
18
19
20
# File 'lib/graphql/relay/node.rb', line 14

def self.method_missing(method_name, *args, &block)
  if instance.respond_to?(method_name)
    instance.send(method_name, *args, &block)
  else
    super
  end
end

Instance Method Details

#create(implementation) ⇒ Object

Return interface and field using implementation



23
24
25
26
27
# File 'lib/graphql/relay/node.rb', line 23

def create(implementation)
  interface = create_interface(implementation)
  field = create_field(implementation, interface)
  [interface, field]
end

#from_global_id(global_id) ⇒ Object

Get type-name & ID from global ID (This reverts the opaque transform)



37
38
39
# File 'lib/graphql/relay/node.rb', line 37

def from_global_id(global_id)
  Base64.decode64(global_id).split("-")
end

#to_global_id(type_name, id) ⇒ Object

Create a global ID for type-name & ID (This is an opaque transform)



31
32
33
# File 'lib/graphql/relay/node.rb', line 31

def to_global_id(type_name, id)
  Base64.strict_encode64("#{type_name}-#{id}")
end