Class: ActiveGraphQL::Fetcher
- Inherits:
-
Support::Fancy
- Object
- Support::Fancy
- ActiveGraphQL::Fetcher
- Defined in:
- lib/activegraphql/fetcher.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#config ⇒ Object
Returns the value of attribute config.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#params ⇒ Object
Returns the value of attribute params.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
-
#default_retriable_options ⇒ Object
Defaults are: - { tries: 1 } if there’s no retriable config.
- #fetch(*graph) ⇒ Object
- #in_locale(locale) ⇒ Object
-
#initialize(attrs) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #query_get(*graph) ⇒ Object
- #retriable_config ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Fetcher
Returns a new instance of Fetcher.
10 11 12 |
# File 'lib/activegraphql/fetcher.rb', line 10 def initialize(attrs) super(attrs) end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
6 7 8 |
# File 'lib/activegraphql/fetcher.rb', line 6 def action @action end |
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/activegraphql/fetcher.rb', line 6 def config @config end |
#klass ⇒ Object
Returns the value of attribute klass.
6 7 8 |
# File 'lib/activegraphql/fetcher.rb', line 6 def klass @klass end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/activegraphql/fetcher.rb', line 6 def params @params end |
#query ⇒ Object
Returns the value of attribute query.
6 7 8 |
# File 'lib/activegraphql/fetcher.rb', line 6 def query @query end |
Instance Method Details
#default_retriable_options ⇒ Object
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)
55 56 57 58 |
# File 'lib/activegraphql/fetcher.rb', line 55 def ||= config[:retriable].blank? ? { tries: 1 } : {} end |
#fetch(*graph) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/activegraphql/fetcher.rb', line 23 def fetch(*graph) response = query_get(*graph) return if response.blank? case response when Hash klass.new(response) when Array response.map { |h| klass.new(h) } else raise Error, "Unexpected response for query: #{response}" end end |
#in_locale(locale) ⇒ Object
18 19 20 21 |
# File 'lib/activegraphql/fetcher.rb', line 18 def in_locale(locale) query.locale = locale if locale.present? self end |
#query_get(*graph) ⇒ Object
38 39 40 |
# File 'lib/activegraphql/fetcher.rb', line 38 def query_get(*graph) Retriable.retriable(retriable_config) { query.get(*graph) } end |
#retriable_config ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/activegraphql/fetcher.rb', line 42 def retriable_config # use defaults if retriable config is not a hash (ie. retriable: true | false) @retriable_config ||= if config[:retriable].is_a?(Hash) .merge(config[:retriable]) else end end |