Class: Zenaton::Services::GraphQL::WorkflowQuery

Inherits:
BaseOperation show all
Defined in:
lib/zenaton/services/graph_ql/workflow_query.rb

Overview

Query parameters to search for a Workflow

Instance Method Summary collapse

Methods inherited from BaseOperation

#intent_id, #query

Constructor Details

#initialize(workflow_name, custom_id, app_env) ⇒ WorkflowQuery

Returns a new instance of WorkflowQuery.



10
11
12
13
14
15
# File 'lib/zenaton/services/graph_ql/workflow_query.rb', line 10

def initialize(workflow_name, custom_id, app_env)
  super
  @workflow_name = workflow_name
  @custom_id = custom_id
  @app_env = app_env
end

Instance Method Details

#bodyObject

The body of the GraphQL request



18
19
20
# File 'lib/zenaton/services/graph_ql/workflow_query.rb', line 18

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

#raw_queryObject

The query to be executed



23
24
25
26
27
28
29
30
31
32
# File 'lib/zenaton/services/graph_ql/workflow_query.rb', line 23

def raw_query
  <<~GQL
    query ($workflowName: String, $customId: ID, $environmentName: String, $programmingLanguage: String) {
      findWorkflow(environmentName: $environmentName, programmingLanguage: $programmingLanguage, customId: $customId, name: $workflowName) {
        name
        properties
      }
    }
  GQL
end

#result(response) ⇒ Object

Parses the results of the query



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zenaton/services/graph_ql/workflow_query.rb', line 45

def result(response)
  data = response['data']
  raise Zenaton::ExternalError, format_errors(response) unless data

  return nil if data['findWorkflow'].nil?

  @properties.object_from(
    data['findWorkflow']['name'],
    @serializer.decode(data['findWorkflow']['properties'])
  )
end

#variablesObject

The variables used in the query



35
36
37
38
39
40
41
42
# File 'lib/zenaton/services/graph_ql/workflow_query.rb', line 35

def variables
  {
    'customId' => @custom_id,
    'environmentName' => @app_env,
    'programmingLanguage' => 'RUBY',
    'workflowName' => @workflow_name
  }
end