class Jeql::Query

Attributes

query_name[R]

Public Class Methods

new(query_name, source_dir, endpoint_config) click to toggle source
# File lib/jeql/query.rb, line 5
def initialize(query_name, source_dir, endpoint_config)
  @query_name = query_name
  @query_file = File.read File.expand_path "./_graphql/#{query_name}.json", source_dir
  @endpoint_config = endpoint_config
end

Public Instance Methods

response() click to toggle source
# File lib/jeql/query.rb, line 11
def response
  @memoized_responses ||= {}
  @memoized_responses[@query_name] ||= execute
end

Private Instance Methods

execute() click to toggle source
# File lib/jeql/query.rb, line 18
def execute
  conn = Faraday.new(url: @endpoint_config["url"], request: timeout_settings)
  response = conn.post do |req|
    req.headers = (@endpoint_config["header"] || {}).merge('Content-Type' => 'application/json')
    req.body = @query_file
  end
end
timeout_settings() click to toggle source
# File lib/jeql/query.rb, line 26
def timeout_settings
  {open_timeout: 2, timeout: 2}
end