Class: Gitlab::Triage::Linear::Migrator::GraphqlClient
- Inherits:
-
Object
- Object
- Gitlab::Triage::Linear::Migrator::GraphqlClient
- Includes:
- QueryLogger
- Defined in:
- lib/gitlab/triage/linear/migrator/graphql_client.rb
Overview
Client class for the GraphQL queries
Constant Summary collapse
- THROTTLE_RETRIES =
3
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#sleep_duration ⇒ Object
Returns the value of attribute sleep_duration.
Instance Method Summary collapse
-
#initialize(endpoint, headers = {}, dry_run: false) ⇒ GraphqlClient
constructor
A new instance of GraphqlClient.
- #mutation(mutation_string, variables = {}) ⇒ Object
- #query(query_string, variables = {}) ⇒ Object
Methods included from QueryLogger
#log_cache_hit, #log_dry_run, #log_error, #log_query, #log_response
Constructor Details
#initialize(endpoint, headers = {}, dry_run: false) ⇒ GraphqlClient
Returns a new instance of GraphqlClient.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gitlab/triage/linear/migrator/graphql_client.rb', line 21 def initialize(endpoint, headers = {}, dry_run: false) @sleep_duration = 30 @endpoint = endpoint @headers = headers @dry_run = dry_run @uri = URI.parse(@endpoint) @http = Net::HTTP.new(@uri.host, @uri.port) @http.use_ssl = @uri.scheme == "https" @cache = {} end |
Instance Attribute Details
#dry_run ⇒ Object
Returns the value of attribute dry_run.
17 18 19 |
# File 'lib/gitlab/triage/linear/migrator/graphql_client.rb', line 17 def dry_run @dry_run end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
16 17 18 |
# File 'lib/gitlab/triage/linear/migrator/graphql_client.rb', line 16 def endpoint @endpoint end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
16 17 18 |
# File 'lib/gitlab/triage/linear/migrator/graphql_client.rb', line 16 def headers @headers end |
#sleep_duration ⇒ Object
Returns the value of attribute sleep_duration.
17 18 19 |
# File 'lib/gitlab/triage/linear/migrator/graphql_client.rb', line 17 def sleep_duration @sleep_duration end |
Instance Method Details
#mutation(mutation_string, variables = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/gitlab/triage/linear/migrator/graphql_client.rb', line 43 def mutation(mutation_string, variables = {}) if @dry_run log_dry_run(mutation_string, variables) return nil end log_query(mutation_string, variables) execute(mutation_string, variables) end |
#query(query_string, variables = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/gitlab/triage/linear/migrator/graphql_client.rb', line 33 def query(query_string, variables = {}) log_query(query_string, variables) cache_key = [query_string, variables].hash return cached_result(cache_key) if cache_hit?(cache_key) result = execute(query_string, variables) cache_result(cache_key, result) result end |