Class: GraphQL::Client::Node

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

Direct Known Subclasses

Document, Fragment, Query

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, fragments) ⇒ Node

Returns a new instance of Node.



25
26
27
28
29
# File 'lib/graphql/client/node.rb', line 25

def initialize(node, fragments)
  @node = node
  @fragments = fragments
  @type = node.query_result_class(shadow: fragments)
end

Instance Attribute Details

#fragmentsObject (readonly)

Returns the value of attribute fragments.



21
22
23
# File 'lib/graphql/client/node.rb', line 21

def fragments
  @fragments
end

#nodeObject (readonly)

Returns the value of attribute node.



19
20
21
# File 'lib/graphql/client/node.rb', line 19

def node
  @node
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/graphql/client/node.rb', line 23

def type
  @type
end

Class Method Details

.scan_interpolated_fragments(str) ⇒ Object



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

def self.scan_interpolated_fragments(str)
  fragments, index = {}, 1
  str = str.gsub(/\.\.\.([a-zA-Z0-9_]+(::[a-zA-Z0-9_]+)+)/) { |m|
    index += 1
    name = "__fragment#{index}__"
    fragments[name.to_sym] = ActiveSupport::Inflector.constantize($1).node
    "...#{name}"
  }
  return str, fragments
end

Instance Method Details

#new(*args) ⇒ Object



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

def new(*args)
  type.new(*args)
end