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

Inherits:
Object
  • Object
show all
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

Direct Known Subclasses

Field, Fragment, Operation, Spread, Typename

Defined Under Namespace

Classes: Field, Fragment, Operation, Spread, Typename

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resolvable

#resolve!

Methods included from Preparable

#prepare!, #prepared_data!, #prepared_data?

Methods included from Organizable

#organize!

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

.kindObject

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

Returns:

  • (Boolean)


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

def assignable?
  false
end

#cache_dumpObject

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

#hashObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

def unresolvable?
  invalid? || skipped?
end