Class: GQLi::Fragment

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

Overview

Fragment wrapper

Instance Attribute Summary collapse

Attributes inherited from Base

#__depth, #__name, #__nodes

Instance Method Summary collapse

Methods inherited from Base

#___, #__on

Constructor Details

#initialize(name, on, &block) ⇒ Fragment

Returns a new instance of Fragment



11
12
13
14
# File 'lib/gqli/fragment.rb', line 11

def initialize(name, on, &block)
  super(name, 0, &block)
  @__on_type = on
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GQLi::Base

Instance Attribute Details

#__on_typeObject (readonly)

Returns the value of attribute __on_type



9
10
11
# File 'lib/gqli/fragment.rb', line 9

def __on_type
  @__on_type
end

Instance Method Details

#to_gqlObject

Serializes to a GraphQL string



17
18
19
20
21
22
23
# File 'lib/gqli/fragment.rb', line 17

def to_gql
  <<~GQL
    fragment #{__name} on #{__on_type} {
    #{__nodes.map(&:to_gql).join("\n")}
    }
  GQL
end