Class: GraphQL::Client::Query::Fragment

Inherits:
Object
  • Object
show all
Includes:
AddInlineFragment, HasSelectionSet
Defined in:
lib/graphql_client/query/fragment.rb

Constant Summary

Constants included from HasSelectionSet

HasSelectionSet::ID_FIELD_NAME, HasSelectionSet::INVALID_FIELD, HasSelectionSet::UNDEFINED_FRAGMENT

Constants included from AddInlineFragment

AddInlineFragment::INVALID_FRAGMENT_TARGET

Instance Attribute Summary collapse

Attributes included from HasSelectionSet

#selection_set

Instance Method Summary collapse

Methods included from HasSelectionSet

#add_connection, #add_field, #add_fields, #add_fragment

Methods included from AddInlineFragment

#add_inline_fragment

Constructor Details

#initialize(name, type, document:) {|_self| ... } ⇒ Fragment

Returns a new instance of Fragment.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
19
# File 'lib/graphql_client/query/fragment.rb', line 12

def initialize(name, type, document:)
  @name = name
  @type = type
  @document = document
  @selection_set = SelectionSet.new

  yield self if block_given?
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



10
11
12
# File 'lib/graphql_client/query/fragment.rb', line 10

def document
  @document
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/graphql_client/query/fragment.rb', line 10

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/graphql_client/query/fragment.rb', line 10

def type
  @type
end

Instance Method Details

#resolver_typeObject



21
22
23
# File 'lib/graphql_client/query/fragment.rb', line 21

def resolver_type
  type
end

#to_definition(indent: '') ⇒ Object



25
26
27
28
29
30
31
# File 'lib/graphql_client/query/fragment.rb', line 25

def to_definition(indent: '')
  indent.dup.tap do |query_string|
    query_string << "fragment #{name} on #{type.name} {\n"
    query_string << selection_set.to_query(indent)
    query_string << "\n#{indent}}\n"
  end
end

#to_query(indent: '') ⇒ Object Also known as: to_s



33
34
35
# File 'lib/graphql_client/query/fragment.rb', line 33

def to_query(indent: '')
  "#{indent}...#{name}"
end