Class: Rails::GraphQL::Request::Component
- Inherits:
-
Object
- Object
- Rails::GraphQL::Request::Component
- Extended by:
- ActiveSupport::Autoload
- Includes:
- Organizable, Preparable, Resolvable
- Defined in:
- lib/rails/graphql/request/component.rb,
lib/rails/graphql/request/component/operation/subscription.rb
Overview
GraphQL Request Component
Component is an abstraction of any possible type of object represented by a not of the document of a request. This class helps building cross-component features, like holding event listeners, setting up common initializer and providing helpers
Defined Under Namespace
Classes: Field, Fragment, Operation, Spread, Typename
Class Method Summary collapse
-
.kind ⇒ Object
Return the kind of the component.
Instance Method Summary collapse
-
#assignable? ⇒ Boolean
Normally, components are not assignable, only fields are.
-
#cache_dump ⇒ Object
Build the cache object.
-
#cache_load(data) ⇒ Object
Organize from cache data.
-
#hash ⇒ Object
Get an identifier of the component.
-
#initialize(node) ⇒ Component
constructor
A new instance of Component.
-
#invalid? ⇒ Boolean
Check if the component is in a invalid state.
-
#invalidate!(type = true) ⇒ Object
Mark the component as invalid.
-
#skip! ⇒ Object
Skip the component.
-
#skipped? ⇒ Boolean
Check if the component is marked as skipped.
-
#unresolvable? ⇒ Boolean
Just a fancy name for invalid or skipped.
Methods included from Resolvable
Methods included from Preparable
#prepare!, #prepared_data!, #prepared_data?
Methods included from Organizable
Constructor Details
#initialize(node) ⇒ Component
Returns a new instance of Component.
42 43 44 |
# File 'lib/rails/graphql/request/component.rb', line 42 def initialize(node) @node = node end |
Class Method Details
.kind ⇒ Object
Return the kind of the component
21 22 23 |
# File 'lib/rails/graphql/request/component.rb', line 21 def kind @kind ||= name.demodulize.underscore.to_sym end |
Instance Method Details
#assignable? ⇒ Boolean
Normally, components are not assignable, only fields are
72 73 74 |
# File 'lib/rails/graphql/request/component.rb', line 72 def assignable? false end |
#cache_dump ⇒ Object
Build the cache object
82 83 84 85 86 87 88 |
# File 'lib/rails/graphql/request/component.rb', line 82 def cache_dump hash = { node: @node } hash[:invalid] = @invalid if defined?(@invalid) && @invalid != :authorization hash[:skipped] = @skipped if defined?(@skipped) && @skipped hash.merge!(super) hash end |
#cache_load(data) ⇒ Object
Organize from cache data
91 92 93 94 95 96 |
# File 'lib/rails/graphql/request/component.rb', line 91 def cache_load(data) @node = data[:node] @invalid = data[:invalid] if data.key?(:invalid) @skipped = data[:skipped] if data.key?(:skipped) super end |
#hash ⇒ Object
Get an identifier of the component
77 78 79 |
# File 'lib/rails/graphql/request/component.rb', line 77 def hash @node.hash end |
#invalid? ⇒ Boolean
Check if the component is in a invalid state
47 48 49 |
# File 'lib/rails/graphql/request/component.rb', line 47 def invalid? defined?(@invalid) && @invalid.present? end |
#invalidate!(type = true) ⇒ Object
Mark the component as invalid
62 63 64 |
# File 'lib/rails/graphql/request/component.rb', line 62 def invalidate!(type = true) @invalid = type end |
#skip! ⇒ Object
Skip the component
67 68 69 |
# File 'lib/rails/graphql/request/component.rb', line 67 def skip! @skipped = true end |
#skipped? ⇒ Boolean
Check if the component is marked as skipped
52 53 54 |
# File 'lib/rails/graphql/request/component.rb', line 52 def skipped? defined?(@skipped) && @skipped end |
#unresolvable? ⇒ Boolean
Just a fancy name for invalid or skipped
57 58 59 |
# File 'lib/rails/graphql/request/component.rb', line 57 def unresolvable? invalid? || skipped? end |