Class: GraphqlConnector::HttpClient
- Inherits:
-
Object
- Object
- GraphqlConnector::HttpClient
- Defined in:
- lib/graphql_connector/http_client.rb
Overview
Wrapper class for HTTParty post query
Instance Method Summary collapse
-
#initialize(uri, headers = {}, connector = {}, httparty_adapter_options = {}) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #mutation(model, inputs, selected_fields, httparty_adapter_options: {}) ⇒ Object
- #query(model, conditions, selected_fields, httparty_adapter_options: {}) ⇒ Object
- #raw_query(query_string, variables: {}, httparty_adapter_options: {}) ⇒ Object
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 = {}, = {}) @uri = uri @headers = headers @connector = connector @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, ) 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, ) 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: {}) = () response = HTTParty.post(@uri, headers: handle_headers, body: { query: query_string, variables: variables }, **) parsed_body = JSON.parse(response.body) verify_response!(parsed_body) parsed_body end |