Class: Zenaton::Services::GraphQL::BaseOperation Abstract
- Inherits:
-
Object
- Object
- Zenaton::Services::GraphQL::BaseOperation
- Defined in:
- lib/zenaton/services/graph_ql/base_operation.rb
Overview
Superclass for graphql queries and mutations.
It expects two methods to be implemented in children classes:
-
#body
-
#raw_query
Direct Known Subclasses
CreateTaskScheduleMutation, CreateWorkflowScheduleMutation, DispatchTaskMutation, DispatchWorkflowMutation, KillWorkflowMutation, PauseWorkflowMutation, ResumeWorkflowMutation, SendEventMutation, WorkflowQuery
Instance Method Summary collapse
-
#body ⇒ Object
To be implemented in subclasses.
-
#initialize ⇒ BaseOperation
constructor
Sets up common dependencies for serialization Don’t forget to call #super in your children #initialize if overriding this method.
-
#intent_id ⇒ String
Sets an unique identifier to the query.
-
#query ⇒ String
Removes duplicate white space from the raw_query.
-
#raw_query ⇒ Object
To be implemented in subclasses.
-
#result(response) ⇒ Object
Default implementation for parsing GraphQL responses Override in subclasses if needed.
Constructor Details
#initialize ⇒ BaseOperation
Sets up common dependencies for serialization Don’t forget to call #super in your children #initialize if overriding this method.
19 20 21 22 |
# File 'lib/zenaton/services/graph_ql/base_operation.rb', line 19 def initialize(*) @serializer = Services::Serializer.new @properties = Services::Properties.new end |
Instance Method Details
#body ⇒ Object
To be implemented in subclasses. Should return the body of the GraphQL request
27 28 29 |
# File 'lib/zenaton/services/graph_ql/base_operation.rb', line 27 def body raise NotImplemented end |
#intent_id ⇒ String
Sets an unique identifier to the query
56 57 58 |
# File 'lib/zenaton/services/graph_ql/base_operation.rb', line 56 def intent_id SecureRandom.uuid end |
#query ⇒ String
Removes duplicate white space from the raw_query
50 51 52 |
# File 'lib/zenaton/services/graph_ql/base_operation.rb', line 50 def query raw_query.gsub(/\s+/, ' ') end |
#raw_query ⇒ Object
To be implemented in subclasses. The actual GraphQL query
34 35 36 |
# File 'lib/zenaton/services/graph_ql/base_operation.rb', line 34 def raw_query raise NotImplemented end |
#result(response) ⇒ Object
Default implementation for parsing GraphQL responses Override in subclasses if needed.
41 42 43 44 45 46 |
# File 'lib/zenaton/services/graph_ql/base_operation.rb', line 41 def result(response) raise Zenaton::ExternalError, format_errors(response) \ if response['errors'] response['data'] end |