class ActiveGraphQL::Fetcher

Attributes

action[RW]
config[RW]
klass[RW]
params[RW]
query[RW]

Public Class Methods

new(attrs) click to toggle source
Calls superclass method
# File lib/activegraphql/fetcher.rb, line 10
def initialize(attrs)
  super(attrs)
end

Public Instance Methods

default_retriable_options() click to toggle source

Defaults are:

- { tries: 1 } if there's no retriable config.
- {} if the config is enabled but with no hash (it will use the defaults from Retriable)
# File lib/activegraphql/fetcher.rb, line 56
def default_retriable_options
  @default_retriable_options ||=
    config[:retriable].blank? ? { tries: 1 } : {}
end
fetch(*graph) click to toggle source
# File lib/activegraphql/fetcher.rb, line 23
def fetch(*graph)
  response = query_get(*graph)

  case response
  when Hash
    return nil if response.empty?
    klass.new(response)
  when Array
    response.map { |h| klass.new(h) }
  when NilClass
    return nil
  else
    raise Error, "Unexpected response for query: #{response}"
  end
end
in_locale(locale) click to toggle source
# File lib/activegraphql/fetcher.rb, line 18
def in_locale(locale)
  query.locale = locale if locale.present?
  self
end
query_get(*graph) click to toggle source
# File lib/activegraphql/fetcher.rb, line 39
def query_get(*graph)
  Retriable.retriable(retriable_config) { query.get(*graph) }
end
retriable_config() click to toggle source
# File lib/activegraphql/fetcher.rb, line 43
def retriable_config
  # use defaults if retriable config is not a hash (ie. retriable: true | false)
  @retriable_config ||=
    if config[:retriable].is_a?(Hash)
      default_retriable_options.merge(config[:retriable])
    else
      default_retriable_options
    end
end