graphlient 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +8 -2
- data/UPGRADING.md +11 -0
- data/graphlient.gemspec +1 -1
- data/lib/graphlient/adapters/http/adapter.rb +18 -0
- data/lib/graphlient/adapters/http/faraday_adapter.rb +8 -1
- data/lib/graphlient/adapters/http/http_adapter.rb +2 -0
- data/lib/graphlient/client.rb +3 -1
- data/lib/graphlient/errors.rb +2 -0
- data/lib/graphlient/errors/http_options_error.rb +6 -0
- data/lib/graphlient/errors/timeout_error.rb +6 -0
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/adapters/http/faraday_adapter_spec.rb +34 -5
- data/spec/graphlient/adapters/http/http_adapter_spec.rb +21 -2
- data/spec/graphlient/client_schema_spec.rb +1 -1
- data/spec/graphlient/static_client_query_spec.rb +1 -1
- data/spec/support/context/dummy_client.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08b4986ba4bf7847c4b14edf75bd14a43726a0f642b4611653ad32e526b51d00'
|
4
|
+
data.tar.gz: e4cfa8a24ea6cf149920a5c4a7068dea0abb0af1c0fce9592ccee3945ed5d794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b98ef7953ca9d6aa06639bbac461acce395e473aa87ccb8764b389107e7932e96488e2b8c37bb8fae7c4c60c25c634c340a24ebb8cd097f31f0b7856f0d7cdd
|
7
|
+
data.tar.gz: 583dd907e0a4d04a2f0c885c9403126453956605ad0d05da495d94f34684411435b28a4dcc25a28f2205a08442c21aa239ecd74866ee55ff8f6cb55b568734ad
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
### 0.
|
1
|
+
### 0.5.0 (Next)
|
2
|
+
|
3
|
+
### 0.4.0
|
4
|
+
* [#72](https://github.com/ashkan18/graphlient/pull/72): Add http_options - [@neroleung](https://github.com/neroleung).
|
5
|
+
* [#71](https://github.com/ashkan18/graphlient/issues/70): Add `Graphlient::Errors::TimeoutError` - [@BenDrozdoff](https://github.com/BenDrozdoff).
|
6
|
+
* [#75](https://github.com/ashkan18/graphlient/pull/75): Support Faraday 1.x - [@jfhinchcliffe](https://github.com/jfhinchcliffe).
|
2
7
|
* Your contribution here.
|
3
8
|
|
4
9
|
### 0.3.7 (14/11/2019)
|
data/README.md
CHANGED
@@ -15,12 +15,16 @@ gem 'graphlient'
|
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
18
|
-
Create a new instance of `Graphlient::Client` with a URL and optional headers.
|
18
|
+
Create a new instance of `Graphlient::Client` with a URL and optional headers/http_options.
|
19
19
|
|
20
20
|
```ruby
|
21
21
|
client = Graphlient::Client.new('https://test-graphql.biz/graphql',
|
22
22
|
headers: {
|
23
23
|
'Authorization' => 'Bearer 123'
|
24
|
+
},
|
25
|
+
http_options: {
|
26
|
+
read_timeout: 20,
|
27
|
+
write_timeout: 30
|
24
28
|
}
|
25
29
|
)
|
26
30
|
```
|
@@ -127,6 +131,8 @@ Unlike graphql-client, Graphlient will always raise an exception unless the quer
|
|
127
131
|
* [Graphlient::Errors::FaradayServerError](lib/graphlient/errors/faraday_server_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
128
132
|
* [Graphlient::Errors::HttpServerError](lib/graphlient/errors/http_server_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
129
133
|
* [Graphlient::Errors::ConnectionFailedError](lib/graphlient/errors/connection_failed_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
134
|
+
* [Graphlient::Errors::TimeoutError](lib/graphlient/errors/timeout_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
135
|
+
* [Graphlient::Errors::HttpOptionsError](lib/graphlient/errors/http_options_error.rb): all NoMethodError raised by HTTP Adapters when given options in `http_options` are invalid
|
130
136
|
|
131
137
|
|
132
138
|
All errors inherit from `Graphlient::Errors::Error` if you need to handle them in bulk.
|
@@ -334,7 +340,7 @@ describe App do
|
|
334
340
|
Graphlient::Client.new('http://test-graphql.biz/graphql') do |client|
|
335
341
|
client.http do |h|
|
336
342
|
h.connection do |c|
|
337
|
-
c.
|
343
|
+
c.adapter Faraday::Adapter::Rack, app
|
338
344
|
end
|
339
345
|
end
|
340
346
|
end
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
Upgrading Graphlient
|
2
2
|
===========================
|
3
3
|
|
4
|
+
### Upgrading to >= 0.4.0
|
5
|
+
|
6
|
+
#### Requires Faraday >= 1.0
|
7
|
+
|
8
|
+
See [#75](https://github.com/ashkan18/graphlient/pull/75).
|
9
|
+
|
10
|
+
#### Changes in error handling of connection refused error
|
11
|
+
|
12
|
+
When the GraphQL request was failing, we were receiving a `Faraday::ServerError`. After 0.4.0, Graphlient
|
13
|
+
will return `Graphlient::Errors::FaradayServerError` instead.
|
14
|
+
|
4
15
|
### Upgrading to >= 0.3.7
|
5
16
|
|
6
17
|
#### Changes in error handling of connection refused error
|
data/graphlient.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.homepage = 'http://github.com/ashkan18/graphlient'
|
15
15
|
s.licenses = ['MIT']
|
16
16
|
s.summary = 'A friendlier Ruby client for consuming GraphQL-based APIs.'
|
17
|
-
s.add_dependency 'faraday'
|
17
|
+
s.add_dependency 'faraday', '>= 1.0'
|
18
18
|
s.add_dependency 'faraday_middleware'
|
19
19
|
s.add_dependency 'graphql-client'
|
20
20
|
end
|
@@ -14,9 +14,27 @@ module Graphlient
|
|
14
14
|
options[:headers] if options
|
15
15
|
end
|
16
16
|
|
17
|
+
def http_options
|
18
|
+
return {} unless options
|
19
|
+
|
20
|
+
options[:http_options] || {}
|
21
|
+
end
|
22
|
+
|
17
23
|
def execute(*)
|
18
24
|
raise NotImplementedError
|
19
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def configure_http_options(client_options)
|
30
|
+
http_options.each do |k, v|
|
31
|
+
begin
|
32
|
+
client_options.send("#{k}=", v)
|
33
|
+
rescue NoMethodError => e
|
34
|
+
raise Graphlient::Errors::HttpOptionsError, e.message
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
20
38
|
end
|
21
39
|
end
|
22
40
|
end
|
@@ -17,8 +17,12 @@ module Graphlient
|
|
17
17
|
response.body
|
18
18
|
rescue Faraday::ConnectionFailed => e
|
19
19
|
raise Graphlient::Errors::ConnectionFailedError, e
|
20
|
+
rescue Faraday::TimeoutError => e
|
21
|
+
raise Graphlient::Errors::TimeoutError, e
|
20
22
|
rescue Faraday::ClientError => e
|
21
23
|
raise Graphlient::Errors::FaradayServerError, e
|
24
|
+
rescue Faraday::ServerError => e
|
25
|
+
raise Graphlient::Errors::FaradayServerError, e
|
22
26
|
end
|
23
27
|
|
24
28
|
def connection
|
@@ -26,10 +30,13 @@ module Graphlient
|
|
26
30
|
c.use Faraday::Response::RaiseError
|
27
31
|
c.request :json
|
28
32
|
c.response :json
|
33
|
+
|
34
|
+
configure_http_options(c.options)
|
35
|
+
|
29
36
|
if block_given?
|
30
37
|
yield c
|
31
38
|
else
|
32
|
-
c.
|
39
|
+
c.adapter Faraday::Adapter::NetHttp
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
data/lib/graphlient/client.rb
CHANGED
@@ -45,7 +45,9 @@ module Graphlient
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def http(&block)
|
48
|
-
|
48
|
+
adapter_options = { headers: @options[:headers], http_options: @options[:http_options] }
|
49
|
+
|
50
|
+
@http ||= http_adapter_class.new(@url, adapter_options, &block)
|
49
51
|
end
|
50
52
|
|
51
53
|
def schema
|
data/lib/graphlient/errors.rb
CHANGED
@@ -4,5 +4,7 @@ require_relative 'errors/server_error'
|
|
4
4
|
require_relative 'errors/graphql_error'
|
5
5
|
require_relative 'errors/execution_error'
|
6
6
|
require_relative 'errors/faraday_server_error'
|
7
|
+
require_relative 'errors/http_options_error'
|
7
8
|
require_relative 'errors/http_server_error'
|
8
9
|
require_relative 'errors/connection_failed_error'
|
10
|
+
require_relative 'errors/timeout_error'
|
data/lib/graphlient/version.rb
CHANGED
@@ -8,29 +8,32 @@ describe Graphlient::Adapters::HTTP::FaradayAdapter do
|
|
8
8
|
Graphlient::Client.new('http://example.com/graphql') do |client|
|
9
9
|
client.http do |h|
|
10
10
|
h.connection do |c|
|
11
|
-
c.
|
11
|
+
c.adapter Faraday::Adapter::Rack, app
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'inserts a middleware into the connection' do
|
18
|
+
expect(client.http.connection.adapter).to eq Faraday::Adapter::Rack
|
18
19
|
expect(client.http.connection.builder.handlers).to eq(
|
19
20
|
[
|
20
21
|
Faraday::Response::RaiseError,
|
21
22
|
FaradayMiddleware::EncodeJson,
|
22
|
-
FaradayMiddleware::ParseJson
|
23
|
-
Faraday::Adapter::Rack
|
23
|
+
FaradayMiddleware::ParseJson
|
24
24
|
]
|
25
25
|
)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context 'with custom url and
|
29
|
+
context 'with custom url, headers and http_options' do
|
30
30
|
let(:url) { 'http://example.com/graphql' }
|
31
31
|
let(:headers) { { 'Foo' => 'bar' } }
|
32
|
+
let(:http_options) { { timeout: timeout, write_timeout: write_timeout } }
|
33
|
+
let(:timeout) { 123 }
|
34
|
+
let(:write_timeout) { 234 }
|
32
35
|
let(:client) do
|
33
|
-
Graphlient::Client.new(url, headers: headers)
|
36
|
+
Graphlient::Client.new(url, headers: headers, http_options: http_options)
|
34
37
|
end
|
35
38
|
|
36
39
|
it 'sets url' do
|
@@ -40,6 +43,19 @@ describe Graphlient::Adapters::HTTP::FaradayAdapter do
|
|
40
43
|
it 'sets headers' do
|
41
44
|
expect(client.http.headers).to eq headers
|
42
45
|
end
|
46
|
+
|
47
|
+
it 'sets http_options' do
|
48
|
+
expect(client.http.connection.options.timeout).to eq(timeout)
|
49
|
+
expect(client.http.connection.options.write_timeout).to eq(write_timeout)
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when http_options contains invalid option' do
|
53
|
+
let(:http_options) { { an_invalid_option: 'an invalid option' } }
|
54
|
+
|
55
|
+
it 'raises Graphlient::Errors::HttpOptionsError' do
|
56
|
+
expect { client.http.connection }.to raise_error(Graphlient::Errors::HttpOptionsError)
|
57
|
+
end
|
58
|
+
end
|
43
59
|
end
|
44
60
|
|
45
61
|
context 'default' do
|
@@ -78,4 +94,17 @@ describe Graphlient::Adapters::HTTP::FaradayAdapter do
|
|
78
94
|
expect { client.schema }.to raise_error(Graphlient::Errors::ConnectionFailedError, expected_error_message)
|
79
95
|
end
|
80
96
|
end
|
97
|
+
|
98
|
+
context 'Faraday Timeout Error' do
|
99
|
+
let(:url) { 'http://example.com/graphql' }
|
100
|
+
let(:client) { Graphlient::Client.new(url) }
|
101
|
+
let(:error_message) { 'Failed to Connect' }
|
102
|
+
|
103
|
+
before do
|
104
|
+
stub_request(:post, url).to_raise(Faraday::TimeoutError.new(Net::ReadTimeout.new(error_message)))
|
105
|
+
end
|
106
|
+
it 'raises a Graphlient Timeout' do
|
107
|
+
expect { client.schema }.to raise_error(Graphlient::Errors::TimeoutError, error_message)
|
108
|
+
end
|
109
|
+
end
|
81
110
|
end
|
@@ -3,11 +3,18 @@ require 'spec_helper'
|
|
3
3
|
describe Graphlient::Adapters::HTTP::HTTPAdapter do
|
4
4
|
let(:app) { Object.new }
|
5
5
|
|
6
|
-
context 'with custom url and
|
6
|
+
context 'with custom url, headers and http_options' do
|
7
7
|
let(:url) { 'http://example.com/graphql' }
|
8
8
|
let(:headers) { { 'Foo' => 'bar' } }
|
9
|
+
let(:http_options) { { read_timeout: read_timeout } }
|
10
|
+
let(:read_timeout) { nil }
|
9
11
|
let(:client) do
|
10
|
-
Graphlient::Client.new(
|
12
|
+
Graphlient::Client.new(
|
13
|
+
url,
|
14
|
+
headers: headers,
|
15
|
+
http_options: http_options,
|
16
|
+
http: Graphlient::Adapters::HTTP::HTTPAdapter
|
17
|
+
)
|
11
18
|
end
|
12
19
|
|
13
20
|
it 'sets adapter' do
|
@@ -21,6 +28,18 @@ describe Graphlient::Adapters::HTTP::HTTPAdapter do
|
|
21
28
|
it 'sets headers' do
|
22
29
|
expect(client.http.headers).to eq headers
|
23
30
|
end
|
31
|
+
|
32
|
+
it 'sets http_options' do
|
33
|
+
expect(client.http.connection.read_timeout).to eq(read_timeout)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when http_options contains invalid option' do
|
37
|
+
let(:http_options) { { an_invalid_option: 'an invalid option' } }
|
38
|
+
|
39
|
+
it 'raises Graphlient::Errors::HttpOptionsError' do
|
40
|
+
expect { client.http.connection }.to raise_error(Graphlient::Errors::HttpOptionsError)
|
41
|
+
end
|
42
|
+
end
|
24
43
|
end
|
25
44
|
|
26
45
|
context 'default' do
|
@@ -19,7 +19,7 @@ describe Graphlient::Client do
|
|
19
19
|
it 'fails with an exception' do
|
20
20
|
expect do
|
21
21
|
client.schema
|
22
|
-
end.to raise_error Graphlient::Errors::
|
22
|
+
end.to raise_error Graphlient::Errors::FaradayServerError do |e|
|
23
23
|
expect(e.to_s).to eq 'the server responded with status 500'
|
24
24
|
expect(e.status_code).to eq 500
|
25
25
|
expect(e.response['errors'].size).to eq 1
|
@@ -18,7 +18,7 @@ RSpec.shared_context 'Dummy Client', shared_context: :metadata do
|
|
18
18
|
Graphlient::Client.new(endpoint, headers: headers) do |client|
|
19
19
|
client.http do |h|
|
20
20
|
h.connection do |c|
|
21
|
-
c.
|
21
|
+
c.adapter Faraday::Adapter::Rack, app
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphlient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday_middleware
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,8 +88,10 @@ files:
|
|
88
88
|
- lib/graphlient/errors/execution_error.rb
|
89
89
|
- lib/graphlient/errors/faraday_server_error.rb
|
90
90
|
- lib/graphlient/errors/graphql_error.rb
|
91
|
+
- lib/graphlient/errors/http_options_error.rb
|
91
92
|
- lib/graphlient/errors/http_server_error.rb
|
92
93
|
- lib/graphlient/errors/server_error.rb
|
94
|
+
- lib/graphlient/errors/timeout_error.rb
|
93
95
|
- lib/graphlient/extensions.rb
|
94
96
|
- lib/graphlient/extensions/query.rb
|
95
97
|
- lib/graphlient/query.rb
|
@@ -137,7 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
- !ruby/object:Gem::Version
|
138
140
|
version: 1.3.6
|
139
141
|
requirements: []
|
140
|
-
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.7.6
|
141
144
|
signing_key:
|
142
145
|
specification_version: 4
|
143
146
|
summary: A friendlier Ruby client for consuming GraphQL-based APIs.
|