Class: Rails::GraphQL::Request::Component::Typename
- Inherits:
-
Rails::GraphQL::Request::Component
- Object
- Rails::GraphQL::Request::Component
- Rails::GraphQL::Request::Component::Typename
- Includes:
- Directives, ValueWriters
- Defined in:
- lib/rails/graphql/request/component/typename.rb
Overview
GraphQL Request Component Typename
Extra component which simulates a field that its only purpose is to return the name of the parent GraphQL object
Constant Summary
Constants included from ValueWriters
Instance Attribute Summary collapse
-
#alias_name ⇒ Object
readonly
Returns the value of attribute alias_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
-
.kind ⇒ Object
Rewrite the kind to always return
:field
.
Instance Method Summary collapse
-
#broadcastable? ⇒ Boolean
Typename is always broadcastable.
-
#cache_load(data) ⇒ Object
Organize from cache data.
-
#gql_name ⇒ Object
Return the name of the field to be used on the response.
-
#initialize(parent, node) ⇒ Typename
constructor
A new instance of Typename.
-
#prepare! ⇒ Object
Prepare is not necessary for this field.
-
#resolve_with!(object) ⇒ Object
Set the value that the field will be resolved as.
-
#write_value(value) ⇒ Object
Write the typename information.
Methods included from Directives
#cache_dump, #directive_events, #directive_listeners, #using?
Methods included from ValueWriters
#format_array_exception, #write_array, #write_array!
Methods inherited from Rails::GraphQL::Request::Component
#assignable?, #cache_dump, #hash, #invalid?, #invalidate!, #skip!, #skipped?, #unresolvable?
Methods included from Resolvable
Methods included from Preparable
#prepared_data!, #prepared_data?
Methods included from Organizable
Constructor Details
#initialize(parent, node) ⇒ Typename
Returns a new instance of Typename.
24 25 26 27 28 29 30 31 |
# File 'lib/rails/graphql/request/component/typename.rb', line 24 def initialize(parent, node) @parent = parent @name = node[0] @alias_name = node[1] super(node) end |
Instance Attribute Details
#alias_name ⇒ Object (readonly)
Returns the value of attribute alias_name.
17 18 19 |
# File 'lib/rails/graphql/request/component/typename.rb', line 17 def alias_name @alias_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/rails/graphql/request/component/typename.rb', line 17 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
17 18 19 |
# File 'lib/rails/graphql/request/component/typename.rb', line 17 def parent @parent end |
Class Method Details
.kind ⇒ Object
Rewrite the kind to always return :field
20 21 22 |
# File 'lib/rails/graphql/request/component/typename.rb', line 20 def self.kind :field end |
Instance Method Details
#broadcastable? ⇒ Boolean
Typename is always broadcastable
52 53 54 |
# File 'lib/rails/graphql/request/component/typename.rb', line 52 def broadcastable? true end |
#cache_load(data) ⇒ Object
Organize from cache data
61 62 63 64 65 66 |
# File 'lib/rails/graphql/request/component/typename.rb', line 61 def cache_load(data) @name = data[:node][0] @alias_name = data[:node][1] super end |
#gql_name ⇒ Object
Return the name of the field to be used on the response
42 43 44 |
# File 'lib/rails/graphql/request/component/typename.rb', line 42 def gql_name alias_name || name end |
#prepare! ⇒ Object
Prepare is not necessary for this field
57 58 |
# File 'lib/rails/graphql/request/component/typename.rb', line 57 def prepare! end |
#resolve_with!(object) ⇒ Object
Set the value that the field will be resolved as
34 35 36 37 38 39 |
# File 'lib/rails/graphql/request/component/typename.rb', line 34 def resolve_with!(object) @typename = object.gql_name resolve! ensure @typename = nil end |
#write_value(value) ⇒ Object
Write the typename information
47 48 49 |
# File 'lib/rails/graphql/request/component/typename.rb', line 47 def write_value(value) response.serialize(Type::Scalar::StringScalar, gql_name, value.itself) end |