activegraphql 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f490b7e893e043ee303228f7d659808aec08f77
4
- data.tar.gz: 3499be7e33802b8c9889db2a06b04fbbfc635d30
3
+ metadata.gz: e3dd6a53135f02f40cbebf52dd7fc5b9141743b2
4
+ data.tar.gz: 25ade92db50b148a2847be36fff757d04a478e6c
5
5
  SHA512:
6
- metadata.gz: 96dfa45e1298a8ada8ce340b74fcde936e663577de144ccaac19ba6e5041d94e579ea6336e831aaa0a44e8b394eb73e32ef01bb8fafe09717e6bc38f636e30cc
7
- data.tar.gz: 71a8365dcda8afe0907c70aa6f09b0e0f328639619ee243082e69db40a618a1550a40ff3ebe753975c66d40b190ccb072862d069bd3c46c17632c2efde82cd70
6
+ metadata.gz: 7639e768128a50b6ea37556fab9b3953950cc6ddb5cbfd6338ec8ae59b6ef4668563d575ca30f28d9bcbae8e9dd6908d2ac705720e9aed34765c591e285b24ae
7
+ data.tar.gz: 85a814d49b16fc3408b5cafbb55877657fce95adcda554957dd240ec26de06ea0364fb1af6f242352151556490a9b318ff45f67863f8705793de79594a3726bf
data/README.md CHANGED
@@ -104,3 +104,29 @@ Any fetcher provides the `in_locale(locale)` method that makes the call to inclu
104
104
  >> MyModel.all.in_locale('es_ES').fetch(:some_attribute).first.some_attribute
105
105
  => "Este es mi texto"
106
106
  ```
107
+
108
+ ## Configuration
109
+ ### Http
110
+ `ActiveGraphQL::Query` uses [HttParty](https://github.com/jnunemaker/httparty) as codebase for http calls.
111
+ The [http options](http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods) used to perform requests can be configured.
112
+
113
+ ```ruby
114
+ class MyModel < ActiveGraphQL::Model
115
+ configure http: { timeout: 0.1 }
116
+ end
117
+ ```
118
+
119
+ ### Retriable
120
+ This gem supports retriable strategy with randomized exponential backoff, based on [Retriable](https://github.com/kamui/retriable).
121
+ Retriable is disabled by default, so `ActiveGraphQL::Model.configure` accepts the available options for [Retriable#retriable](https://github.com/kamui/retriable#options).
122
+
123
+ NOTE: Configuring `retriable: true` will activate `Retriable` with its defaults.
124
+
125
+ ```ruby
126
+ class MyModel < ActiveGraphQL::Model
127
+ configure retriable: { on: [Timeout::Error, Errno::ECONNRESET],
128
+ tries: 10,
129
+ base_interval: 0.5,
130
+ max_interval: 1 }
131
+ end
132
+ ```
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'hashie', '~> 3.4'
26
26
  spec.add_dependency 'activesupport', '~> 4.2'
27
27
  spec.add_dependency 'httparty', '~> 0.13'
28
+ spec.add_dependency 'retriable', '~> 2.0'
28
29
  end
@@ -1,8 +1,9 @@
1
1
  require 'activegraphql/support/fancy'
2
+ require 'retriable'
2
3
 
3
4
  module ActiveGraphQL
4
5
  class Fetcher < Support::Fancy
5
- attr_accessor :url, :klass, :action, :params, :query
6
+ attr_accessor :config, :klass, :action, :params, :query
6
7
 
7
8
  class Error < StandardError; end
8
9
 
@@ -11,7 +12,7 @@ module ActiveGraphQL
11
12
  end
12
13
 
13
14
  def query
14
- @query ||= Query.new(url: url, action: action, params: params)
15
+ @query ||= Query.new(config: config, action: action, params: params)
15
16
  end
16
17
 
17
18
  def in_locale(locale)
@@ -20,7 +21,8 @@ module ActiveGraphQL
20
21
  end
21
22
 
22
23
  def fetch(*graph)
23
- response = query.get(*graph)
24
+ response = query_get(*graph)
25
+
24
26
  return if response.blank?
25
27
 
26
28
  case response
@@ -32,5 +34,27 @@ module ActiveGraphQL
32
34
  raise Error, "Unexpected response for query: #{response}"
33
35
  end
34
36
  end
37
+
38
+ def query_get(*graph)
39
+ Retriable.retriable(retriable_config) { query.get(*graph) }
40
+ end
41
+
42
+ def retriable_config
43
+ # use defaults if retriable config is not a hash (ie. retriable: true | false)
44
+ @retriable_config ||=
45
+ if config[:retriable].is_a?(Hash)
46
+ default_retriable_options.merge(config[:retriable])
47
+ else
48
+ default_retriable_options
49
+ end
50
+ end
51
+
52
+ # Defaults are:
53
+ # - { tries: 1 } if there's no retriable config.
54
+ # - {} if the config is enabled but with no hash (it will use the defaults from Retriable)
55
+ def default_retriable_options
56
+ @default_retriable_options ||=
57
+ config[:retriable].blank? ? { tries: 1 } : {}
58
+ end
35
59
  end
36
60
  end
@@ -6,7 +6,7 @@ module ActiveGraphQL
6
6
  class Error < StandardError; end
7
7
 
8
8
  class << self
9
- attr_accessor :url
9
+ attr_accessor :config
10
10
 
11
11
  # This provides ability to configure the class inherited from here.
12
12
  # Also field classes will have the configuration.
@@ -19,13 +19,14 @@ module ActiveGraphQL
19
19
  # class ModelToMyService < BaseModelToMyService
20
20
  # end
21
21
  #
22
- # BaseModelToMyService.url
23
- # => "http://localhost:3000/graphql"
22
+ # BaseModelToMyService.config
23
+ # => { url: "http://localhost:3000/graphql" }
24
24
  #
25
25
  # ModelToMyService.url
26
- # => "http://localhost:3000/graphql"
27
- def configure(url: nil)
28
- configurable_class.url = url
26
+ # => { url: "http://localhost:3000/graphql" }
27
+ def configure(config = {})
28
+ configurable_class.config ||= {}
29
+ configurable_class.config.merge!(config)
29
30
  end
30
31
 
31
32
  # Resolves the class who is extending from ActiveGraphql::Model.
@@ -49,7 +50,7 @@ module ActiveGraphQL
49
50
  end
50
51
 
51
52
  def build_fetcher(action, params = nil)
52
- Fetcher.new(url: configurable_class.url,
53
+ Fetcher.new(config: configurable_class.config,
53
54
  klass: self,
54
55
  action: action,
55
56
  params: params)
@@ -4,14 +4,14 @@ require 'activegraphql/support/fancy'
4
4
 
5
5
  module ActiveGraphQL
6
6
  class Query < Support::Fancy
7
- attr_accessor :url, :action, :params, :locale, :graph, :response
7
+ attr_accessor :config, :action, :params, :locale, :graph, :response
8
8
 
9
9
  class ServerError < StandardError; end
10
10
 
11
11
  def get(*graph)
12
12
  self.graph = graph
13
13
 
14
- self.response = HTTParty.get(url, request_options)
14
+ self.response = HTTParty.get(config[:url], request_options)
15
15
 
16
16
  raise(ServerError, response_error_messages) if response_errors.present?
17
17
  response_data
@@ -20,6 +20,7 @@ module ActiveGraphQL
20
20
  def request_options
21
21
  { query: { query: to_s } }.tap do |opts|
22
22
  opts.merge!(headers: { 'Accept-Language' => locale.to_s }) if locale.present?
23
+ opts.merge!(config[:http]) if config[:http].present?
23
24
  end
24
25
  end
25
26
 
@@ -1,3 +1,3 @@
1
1
  module ActiveGraphQL
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activegraphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wakoopa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-15 00:00:00.000000000 Z
11
+ date: 2016-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: retriable
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
97
111
  description: ''
98
112
  email:
99
113
  - info@wakoopa.com
@@ -137,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
151
  version: '0'
138
152
  requirements: []
139
153
  rubyforge_project:
140
- rubygems_version: 2.4.5.1
154
+ rubygems_version: 2.5.1
141
155
  signing_key:
142
156
  specification_version: 4
143
157
  summary: Ruby client for GraphQL services