Class: Rails::GraphQL::Request::Component::Fragment
- Inherits:
-
Rails::GraphQL::Request::Component
- Object
- Rails::GraphQL::Request::Component
- Rails::GraphQL::Request::Component::Fragment
- 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
-
#current_object ⇒ Object
readonly
Returns the value of attribute current_object.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#type_klass ⇒ Object
readonly
Returns the value of attribute type_klass.
Attributes included from SelectionSet
Instance Method Summary collapse
-
#broadcastable? ⇒ Boolean
Check if all the sub fields are broadcastable.
-
#cache_dump ⇒ Object
Build the cache object.
-
#cache_load(data) ⇒ Object
Organize from cache data.
-
#initialize(request, node) ⇒ Fragment
constructor
A new instance of Fragment.
-
#operation ⇒ Object
Access the operation through the Request::Arguments.
-
#prepared? ⇒ Boolean
Check if the fragment has been prepared already.
-
#resolve_with!(object) ⇒ Object
Only resolve if the
type_klassis equivalent to the givenobject. -
#typename ⇒ Object
Spread should always be performed with a current object, thus the typename comes from it.
-
#used_fragments ⇒ Object
Stores all the used nested fragments.
-
#used_variables ⇒ Object
Stores all the used variables.
-
#variables ⇒ Object
Return a lazy loaded variable proc.
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
Methods included from Preparable
#prepare!, #prepared_data!, #prepared_data?
Methods included from Organizable
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_object ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/rails/graphql/request/component/fragment.rb', line 15 def name @name end |
#request ⇒ Object (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_klass ⇒ Object (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
27 28 29 |
# File 'lib/rails/graphql/request/component/fragment.rb', line 27 def broadcastable? selection.each_value.all?(&:broadcastable?) end |
#cache_dump ⇒ Object
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 |
#operation ⇒ Object
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
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 |
#typename ⇒ Object
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_fragments ⇒ Object
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_variables ⇒ Object
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 |
#variables ⇒ Object
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 |