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



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

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

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



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

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

  Rails.logger.debug "Querying Graphql host: #{host_type}, query: #{query}, variables: #{variables.inspect}"
  result = client.query(query, variables)

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

  Rails.logger.debug "Graphql result: #{return_values.inspect}"

  return_values
end