Class: Rails::GraphQL::Request::Component::Operation
- Inherits:
-
Rails::GraphQL::Request::Component
- Object
- Rails::GraphQL::Request::Component
- Rails::GraphQL::Request::Component::Operation
- Extended by:
- ActiveSupport::Autoload
- Includes:
- Directives, SelectionSet
- Defined in:
- lib/rails/graphql/request/component/operation.rb
Overview
GraphQL Request Component Operation
This class holds information about a given operation. This will guide the validation and execution of it.
Direct Known Subclasses
Defined Under Namespace
Classes: Subscription
Constant Summary collapse
- Query =
Query is default behavior, so it doesn’t need a whole class
Class.new(self) { redefine_singleton_method(:query?) { true } }
- Mutation =
Class.new(self) { redefine_singleton_method(:mutation?) { true } }
Instance Attribute Summary collapse
-
#arguments ⇒ Object
(also: #all_arguments)
readonly
Returns the value of attribute arguments.
-
#name ⇒ Object
(also: #gql_name)
readonly
Returns the value of attribute name.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#variables ⇒ Object
(also: #vars)
readonly
Returns the value of attribute variables.
Attributes included from SelectionSet
Class Method Summary collapse
-
.build(request, node) ⇒ Object
Helper method to initialize an operation given the node.
-
.kind ⇒ Object
Rewrite the kind to always return
:operation
. -
.mutation? ⇒ Boolean
Defines if the current operation is a mutation type.
-
.query? ⇒ Boolean
Defines if the current operation is a query type.
-
.subscription? ⇒ Boolean
Defines if the current operation is a subscription type.
- .type ⇒ Object
Instance Method Summary collapse
-
#cache_dump ⇒ Object
Build the cache object.
-
#cache_load(data) ⇒ Object
Organize from cache data.
-
#fields_source ⇒ Object
The list of fields comes from the
fields_for
of the same type as thetype
of the operation. -
#hash ⇒ Object
The hash of operations must take into consideration the used fragments.
-
#initialize(request, node) ⇒ Operation
constructor
A new instance of Operation.
-
#log_source ⇒ Object
A fast way to access the correct display name for log or errors.
-
#memo ⇒ Object
Support memory object to save information across the iteration.
-
#resolve_invalid ⇒ Object
Add a empty entry if the operation has a name.
-
#type_klass ⇒ Object
Allow accessing the fake type form the schema.
-
#typename ⇒ Object
The typename is always based on the fake name used for the set of schema fields.
-
#used_fragments ⇒ Object
Stores all the used fragments.
-
#used_variables ⇒ Object
Stores all the used variables to report not used ones.
Methods included from Directives
#directive_events, #directive_listeners, #using?
Methods inherited from Rails::GraphQL::Request::Component
#assignable?, #invalid?, #invalidate!, #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) ⇒ Operation
Returns a new instance of Operation.
63 64 65 66 67 68 69 70 |
# File 'lib/rails/graphql/request/component/operation.rb', line 63 def initialize(request, node) @name = node[1] @request = request super(node) check_invalid_operation! end |
Instance Attribute Details
#arguments ⇒ Object (readonly) Also known as: all_arguments
Returns the value of attribute arguments.
56 57 58 |
# File 'lib/rails/graphql/request/component/operation.rb', line 56 def arguments @arguments end |
#name ⇒ Object (readonly) Also known as: gql_name
Returns the value of attribute name.
56 57 58 |
# File 'lib/rails/graphql/request/component/operation.rb', line 56 def name @name end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
56 57 58 |
# File 'lib/rails/graphql/request/component/operation.rb', line 56 def request @request end |
#variables ⇒ Object (readonly) Also known as: vars
Returns the value of attribute variables.
56 57 58 |
# File 'lib/rails/graphql/request/component/operation.rb', line 56 def variables @variables end |
Class Method Details
.build(request, node) ⇒ Object
Helper method to initialize an operation given the node
20 21 22 23 24 |
# File 'lib/rails/graphql/request/component/operation.rb', line 20 def build(request, node) request.build(const_get(node.type.to_s.classify, false), request, node) rescue ::NameError raise NameError, +%[Unable to initialize "#{node.type}" operation.] end |
.kind ⇒ Object
Rewrite the kind to always return :operation
27 28 29 |
# File 'lib/rails/graphql/request/component/operation.rb', line 27 def kind :operation end |
.mutation? ⇒ Boolean
Defines if the current operation is a mutation type
37 38 39 |
# File 'lib/rails/graphql/request/component/operation.rb', line 37 def mutation? false end |
.query? ⇒ Boolean
Defines if the current operation is a query type
32 33 34 |
# File 'lib/rails/graphql/request/component/operation.rb', line 32 def query? false end |
.subscription? ⇒ Boolean
Defines if the current operation is a subscription type
42 43 44 |
# File 'lib/rails/graphql/request/component/operation.rb', line 42 def subscription? false end |
.type ⇒ Object
17 |
# File 'lib/rails/graphql/request/component/operation.rb', line 17 alias type kind |
Instance Method Details
#cache_dump ⇒ Object
Build the cache object
126 127 128 |
# File 'lib/rails/graphql/request/component/operation.rb', line 126 def cache_dump super.merge(type: self.class) end |
#cache_load(data) ⇒ Object
Organize from cache data
131 132 133 134 135 |
# File 'lib/rails/graphql/request/component/operation.rb', line 131 def cache_load(data) @name = data[:node][1] super end |
#fields_source ⇒ Object
The list of fields comes from the fields_for
of the same type as the type
of the operation
74 75 76 |
# File 'lib/rails/graphql/request/component/operation.rb', line 74 def fields_source schema.fields_for(type) end |
#hash ⇒ Object
The hash of operations must take into consideration the used fragments
117 118 119 120 121 122 123 |
# File 'lib/rails/graphql/request/component/operation.rb', line 117 def hash return super unless defined?(@used_fragments) super ^ used_fragments.reduce(0) do |value, fragment| value ^ request.fragments[fragment].hash end end |
#log_source ⇒ Object
A fast way to access the correct display name for log or errors
112 113 114 |
# File 'lib/rails/graphql/request/component/operation.rb', line 112 def log_source @log_source ||= name.blank? ? type : +"#{name} #{type}" end |
#memo ⇒ Object
Support memory object to save information across the iteration
92 93 94 |
# File 'lib/rails/graphql/request/component/operation.rb', line 92 def memo @memo ||= OpenStruct.new end |
#resolve_invalid ⇒ Object
Add a empty entry if the operation has a name
97 98 99 |
# File 'lib/rails/graphql/request/component/operation.rb', line 97 def resolve_invalid response.safe_add(name, nil) if stacked_selection? end |
#type_klass ⇒ Object
Allow accessing the fake type form the schema. It’s used for inline spreads without a specified type
80 81 82 83 |
# File 'lib/rails/graphql/request/component/operation.rb', line 80 def type_klass return @type_klass if defined?(@type_klass) @type_klass = schema.public_send("#{type}_type") end |
#typename ⇒ Object
The typename is always based on the fake name used for the set of schema fields
87 88 89 |
# File 'lib/rails/graphql/request/component/operation.rb', line 87 def typename schema.type_name_for(type) end |
#used_fragments ⇒ Object
Stores all the used fragments
107 108 109 |
# File 'lib/rails/graphql/request/component/operation.rb', line 107 def used_fragments @used_fragments ||= Set.new end |
#used_variables ⇒ Object
Stores all the used variables to report not used ones
102 103 104 |
# File 'lib/rails/graphql/request/component/operation.rb', line 102 def used_variables @used_variables ||= Set.new end |