Class: GraphqlConnector::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_connector/http_client.rb

Overview

Wrapper class for HTTParty post query

Instance Method Summary collapse

Constructor Details

#initialize(uri, headers = {}, connector = {}, httparty_adapter_options = {}) ⇒ HttpClient

Returns a new instance of HttpClient.



6
7
8
9
10
11
# File 'lib/graphql_connector/http_client.rb', line 6

def initialize(uri, headers = {}, connector = {}, httparty_adapter_options = {})
  @uri = uri
  @headers = headers
  @connector = connector
  @httparty_adapter_options = httparty_adapter_options
end

Instance Method Details

#mutation(model, inputs, selected_fields, httparty_adapter_options: {}) ⇒ Object



18
19
20
21
# File 'lib/graphql_connector/http_client.rb', line 18

def mutation(model, inputs, selected_fields, httparty_adapter_options: {})
  query_string = Formatters::MutationFormat.new(model, inputs, selected_fields).create
  format_body(query_string, model, httparty_adapter_options)
end

#query(model, conditions, selected_fields, httparty_adapter_options: {}) ⇒ Object



13
14
15
16
# File 'lib/graphql_connector/http_client.rb', line 13

def query(model, conditions, selected_fields, httparty_adapter_options: {})
  query_string = Formatters::QueryFormat.new(model, conditions, selected_fields).create
  format_body(query_string, model, httparty_adapter_options)
end

#raw_query(query_string, variables: {}, httparty_adapter_options: {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql_connector/http_client.rb', line 23

def raw_query(query_string, variables: {}, httparty_adapter_options: {})
  adapter_options = combined_adapter_options(httparty_adapter_options)
  response = HTTParty.post(@uri,
                           headers: handle_headers,
                           body: { query: query_string, variables: variables },
                           **adapter_options)
  parsed_body = JSON.parse(response.body)
  verify_response!(parsed_body)
  parsed_body
end