Class: Rails::GraphQL::Request::Component::Fragment

Inherits:
Rails::GraphQL::Request::Component show all
Includes:
Directives, SelectionSet
Defined in:
lib/rails/graphql/request/component/fragment.rb

Overview

GraphQL Request Component Fragment

This class holds information about a given fragment defined using the fragment statement during an execution. This will guide the validation and execution of it.

Instance Attribute Summary collapse

Attributes included from SelectionSet

#selection

Instance Method Summary collapse

Methods included from Directives

#directive_events, #directive_listeners, #using?

Methods inherited from Rails::GraphQL::Request::Component

#assignable?, #hash, #invalid?, #invalidate!, kind, #skip!, #skipped?, #unresolvable?

Methods included from Resolvable

#resolve!

Methods included from Preparable

#prepare!, #prepared_data!, #prepared_data?

Methods included from Organizable

#organize!

Constructor Details

#initialize(request, node) ⇒ Fragment

Returns a new instance of Fragment.



17
18
19
20
21
22
23
24
# File 'lib/rails/graphql/request/component/fragment.rb', line 17

def initialize(request, node)
  @name = node[0]
  @request = request

  super(node)

  check_duplicated_fragment!
end

Instance Attribute Details

#current_objectObject (readonly)

Returns the value of attribute current_object.



15
16
17
# File 'lib/rails/graphql/request/component/fragment.rb', line 15

def current_object
  @current_object
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/rails/graphql/request/component/fragment.rb', line 15

def name
  @name
end

#requestObject (readonly)

Returns the value of attribute request.



15
16
17
# File 'lib/rails/graphql/request/component/fragment.rb', line 15

def request
  @request
end

#type_klassObject (readonly)

Returns the value of attribute type_klass.



15
16
17
# File 'lib/rails/graphql/request/component/fragment.rb', line 15

def type_klass
  @type_klass
end

Instance Method Details

#broadcastable?Boolean

Check if all the sub fields are broadcastable

Returns:

  • (Boolean)


27
28
29
# File 'lib/rails/graphql/request/component/fragment.rb', line 27

def broadcastable?
  selection.each_value.all?(&:broadcastable?)
end

#cache_dumpObject

Build the cache object



73
74
75
# File 'lib/rails/graphql/request/component/fragment.rb', line 73

def cache_dump
  super.merge(type_klass: all_to_gid(type_klass))
end

#cache_load(data) ⇒ Object

Organize from cache data



78
79
80
81
82
83
# File 'lib/rails/graphql/request/component/fragment.rb', line 78

def cache_load(data)
  @name = data[:node][0]
  @type_klass = all_from_gid(data[:type_klass])

  super
end

#operationObject

Access the operation through the Request::Arguments



42
43
44
# File 'lib/rails/graphql/request/component/fragment.rb', line 42

def operation
  Request::Arguments.operation
end

#prepared?Boolean

Check if the fragment has been prepared already

Returns:

  • (Boolean)


32
33
34
# File 'lib/rails/graphql/request/component/fragment.rb', line 32

def prepared?
  defined?(@prepared) && @prepared
end

#resolve_with!(object) ⇒ Object

Only resolve if the type_klass is equivalent to the given object



63
64
65
66
67
68
69
70
# File 'lib/rails/graphql/request/component/fragment.rb', line 63

def resolve_with!(object)
  return if unresolvable?

  @current_object = object
  resolve!
ensure
  @current_object = nil
end

#typenameObject

Spread should always be performed with a current object, thus the typename comes from it



58
59
60
# File 'lib/rails/graphql/request/component/fragment.rb', line 58

def typename
  @current_object.gql_name
end

#used_fragmentsObject

Stores all the used nested fragments



52
53
54
# File 'lib/rails/graphql/request/component/fragment.rb', line 52

def used_fragments
  return @used_fragments if defined?(@used_fragments)
end

#used_variablesObject

Stores all the used variables



47
48
49
# File 'lib/rails/graphql/request/component/fragment.rb', line 47

def used_variables
  return @used_variables if defined?(@used_variables)
end

#variablesObject

Return a lazy loaded variable proc



37
38
39
# File 'lib/rails/graphql/request/component/fragment.rb', line 37

def variables
  Request::Arguments.lazy
end