Class: Istox::GraphqlClient

Inherits:
Object
  • Object
show all
Defined in:
lib/istox/helpers/graphql_client.rb

Class Method Summary collapse

Class Method Details

.add_host(host_type, url) ⇒ Object



7
8
9
10
# File 'lib/istox/helpers/graphql_client.rb', line 7

def add_host(host_type, url)
  @@hosts = {} unless defined?(@@hosts)
  init_host(host_type, url)
end

.query(host_type, query, variables = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/istox/helpers/graphql_client.rb', line 12

def query(host_type, query, variables = {})
  client = @@hosts[host_type]

  raise "Please make sure you have initialised graphql cient for host #{host_type}" unless client

  log.info "Querying Graphql host: #{host_type}, query: #{query}, variables: #{variables.inspect}"
  result = client.query(query, variables)

  return_values = ::Istox::CommonHelper.to_open_struct(result&.data)

  log.info "Graphql result: #{return_values.inspect}"

  return_values
end