Class: Zenaton::Services::GraphQL::DispatchWorkflowMutation

Inherits:
BaseOperation
  • Object
show all
Includes:
Concerns::Workflow
Defined in:
lib/zenaton/services/graph_ql/dispatch_workflow_mutation.rb

Overview

Mutation parameters for executing a workflow

Constant Summary

Constants included from Concerns::Workflow

Concerns::Workflow::MAX_ID_SIZE

Instance Method Summary collapse

Methods inherited from BaseOperation

#intent_id, #query, #result

Constructor Details

#initialize(workflow, app_env) ⇒ DispatchWorkflowMutation

Returns a new instance of DispatchWorkflowMutation.

Raises:



14
15
16
17
18
19
# File 'lib/zenaton/services/graph_ql/dispatch_workflow_mutation.rb', line 14

def initialize(workflow, app_env)
  super
  @workflow = workflow
  @app_env = app_env
  validate_custom_id
end

Instance Method Details

#bodyObject

The body of the GraphQL request



22
23
24
# File 'lib/zenaton/services/graph_ql/dispatch_workflow_mutation.rb', line 22

def body
  { 'query' => query, 'variables' => variables }
end

#raw_queryObject

The query to be executed



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/zenaton/services/graph_ql/dispatch_workflow_mutation.rb', line 27

def raw_query
  <<~GQL
    mutation dispatchWorkflow($input: DispatchWorkflowInput!) {
      dispatchWorkflow(input: $input) {
        workflow {
          id
        }
      }
    }
  GQL
end

#variablesObject

rubocop:disable Metrics/MethodLength The variables used in the query



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zenaton/services/graph_ql/dispatch_workflow_mutation.rb', line 41

def variables
  {
    'input' => {
      'customId' => @workflow.id.try(:to_s),
      'environmentName' => @app_env,
      'intentId' => intent_id,
      'programmingLanguage' => 'RUBY',
      'name' => workflow_name,
      'canonicalName' => @workflow.class.name,
      'data' => @serializer.encode(@properties.from(@workflow))
    }
  }
end