Class: Ecoportal::API::GraphQL::Logic::Mutation
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::Logic::Mutation
- Includes:
- Common::GraphQL::ClassHelpers
- Defined in:
- lib/ecoportal/api/graphql/logic/mutation.rb
Direct Known Subclasses
Mutation::ContractorEntity::Create, Mutation::LocationStructure::ApplyCommands
Defined Under Namespace
Classes: GenericInput, GenericPayload
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
-
.field_name(str = nil) ⇒ Object
Used to obtain the full
pathin the GraphQL query by usingbase_path.
Instance Method Summary collapse
- #access_point(path = []) ⇒ Object
-
#initialize(client, path: nil, base_path: []) ⇒ Mutation
constructor
A new instance of Mutation.
-
#path(field_name = self.class.field_name) ⇒ Object
Resolves the
pathby usingpathorbase_path+class.field_name. -
#query(input:, path: self.path, &block) ⇒ Class
Query rely that manages the different blocks.
- #response_class ⇒ Object
Constructor Details
#initialize(client, path: nil, base_path: []) ⇒ Mutation
Returns a new instance of Mutation.
35 36 37 38 39 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 35 def initialize(client, path: nil, base_path: []) @path = path @base_path = base_path @client = client end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
33 34 35 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 33 def base_path @base_path end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
32 33 34 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 32 def client @client end |
Class Method Details
.field_name(str = nil) ⇒ Object
it is meant for reusability of queries from different end-points
Used to obtain the full path in the GraphQL query by using base_path
22 23 24 25 26 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 22 def field_name(str = nil) return @field_name unless str @field_name = nil @field_name = str.to_s if str end |
Instance Method Details
#access_point(path = []) ⇒ Object
65 66 67 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 65 def access_point(path = []) path.last end |
#path(field_name = self.class.field_name) ⇒ Object
Resolves the path by using path or base_path + class.field_name.
42 43 44 45 46 47 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 42 def path(field_name = self.class.field_name) result = @path result ||= default_path if self.respond_to?(:default_path, true) result ||= (base_path + [field_name]) if base_path && field_name result end |
#query(input:, path: self.path, &block) ⇒ Class
Query rely that manages the different blocks.
51 52 53 54 55 56 57 58 59 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 51 def query(input:, path: self.path, &block) request(*path) do client.query(input: as_input(input), &basic_block(&block)) end rescue Faraday::ParsingError => e puts "Internal Error with these input ('#{input.class}'):" pp input raise end |
#response_class ⇒ Object
61 62 63 |
# File 'lib/ecoportal/api/graphql/logic/mutation.rb', line 61 def response_class payload_class end |