graphlient 0.3.7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +29 -0
- data/.github/workflows/danger.yml +20 -0
- data/.github/workflows/rubocop.yml +19 -0
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +36 -18
- data/Gemfile +1 -1
- data/README.md +57 -4
- 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 +5 -3
- data/lib/graphlient/errors/http_options_error.rb +6 -0
- data/lib/graphlient/errors/timeout_error.rb +6 -0
- data/lib/graphlient/errors.rb +2 -0
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/adapters/http/faraday_adapter_spec.rb +36 -5
- data/spec/graphlient/adapters/http/http_adapter_spec.rb +21 -2
- data/spec/graphlient/client_query_spec.rb +36 -6
- data/spec/graphlient/client_schema_spec.rb +1 -1
- data/spec/graphlient/static_client_query_spec.rb +1 -1
- data/spec/graphlient/webmock_client_query_spec.rb +40 -0
- data/spec/support/context/dummy_client.rb +1 -1
- data/spec/support/fixtures/invoice_api.json +1289 -0
- data/spec/support/mutations/create_invoice.rb +1 -0
- data/spec/support/queries/query.rb +23 -0
- data/spec/support/types/invoice_type.rb +6 -0
- metadata +16 -11
- data/.ruby-version +0 -1
- data/.travis.yml +0 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b777ec75d94d228faa748cadb28c1687b16a377892138a9fc8d1048773b8853
|
|
4
|
+
data.tar.gz: a3bc9f948ffa5c4fe6368282834b7cd4e7addc00b7d1c90ced575ce41e8a8b3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc0080c0fab50ac5ecee6815fb24e6b216cba32558d010ebd3d9661581b55f3b3fca8b70e11f0e61f96eb471931645c12b3a3b8c2361909da31a15c650ab6bcb
|
|
7
|
+
data.tar.gz: feb39198706b8b9650da8f6f35f080744df668420d948f2b7d69d84dd3b812301542d5735d1a69f77d865706e5853703861fe440a1ab47ea2cfef3b91712f794
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
entry:
|
|
14
|
+
- { ruby: 2.7.2 }
|
|
15
|
+
- { ruby: 3.0.0 }
|
|
16
|
+
- { ruby: 3.1.2 }
|
|
17
|
+
- { ruby: "ruby-head", ignore: true }
|
|
18
|
+
- { ruby: "jruby-9.1.17", ignore: true }
|
|
19
|
+
- { ruby: "jruby-head", ignore: true }
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v3
|
|
22
|
+
- name: Set up Ruby
|
|
23
|
+
uses: ruby/setup-ruby@v1
|
|
24
|
+
with:
|
|
25
|
+
ruby-version: ${{ matrix.entry.ruby }}
|
|
26
|
+
bundler-cache: true
|
|
27
|
+
- name: Run tests
|
|
28
|
+
continue-on-error: ${{ matrix.entry.ignore || false }}
|
|
29
|
+
run: bundle exec rspec spec/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Danger
|
|
2
|
+
|
|
3
|
+
on: pull_request
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
danger:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v3
|
|
10
|
+
with:
|
|
11
|
+
fetch-depth: 0
|
|
12
|
+
- name: Set up Ruby
|
|
13
|
+
uses: ruby/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby-version: 2.7.2
|
|
16
|
+
bundler-cache: true
|
|
17
|
+
- run: |
|
|
18
|
+
# the personal token is public, this is ok, base64 encode to avoid tripping Github
|
|
19
|
+
TOKEN=$(echo -n NWY1ZmM5MzEyMzNlYWY4OTZiOGU3MmI3MWQ3Mzk0MzgxMWE4OGVmYwo= | base64 --decode)
|
|
20
|
+
DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Rubocop
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
rubocop:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v3
|
|
13
|
+
- name: Set up Ruby
|
|
14
|
+
uses: ruby/setup-ruby@v1
|
|
15
|
+
with:
|
|
16
|
+
ruby-version: 2.7.2
|
|
17
|
+
bundler-cache: true
|
|
18
|
+
- name: Run rubocop
|
|
19
|
+
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,61 +1,79 @@
|
|
|
1
|
-
### 0.
|
|
2
|
-
|
|
1
|
+
### 0.6.0 (2022/06/11)
|
|
2
|
+
|
|
3
|
+
* [#87](https://github.com/ashkan18/graphlient/pull/87): Raised `ExecutionError` with partial error response - [@QQism](https://github.com/QQism).
|
|
4
|
+
* [#90](https://github.com/ashkan18/graphlient/pull/90): Added support for Ruby 3.1 - [@QQism](https://github.com/QQism).
|
|
5
|
+
* [#90](https://github.com/ashkan18/graphlient/pull/90): Dropped support for Ruby 2.5 - [@QQism](https://github.com/QQism).
|
|
6
|
+
* [#91](https://github.com/ashkan18/graphlient/pull/91): Update GHA for `danger` with right permissions - [@QQism](https://github.com/QQism).
|
|
7
|
+
* [#89](https://github.com/ashkan18/graphlient/pull/89): Replace Travis CI with Github Actions - [@QQism](https://github.com/QQism).
|
|
8
|
+
|
|
9
|
+
### 0.5.0 (2020/12/28)
|
|
10
|
+
|
|
11
|
+
* [#81](https://github.com/ashkan18/graphlient/pull/81): Make graphlient run on ruby 3.0 - [@Burgestrand](https://github.com/Burgestrand).
|
|
12
|
+
* [#79](https://github.com/ashkan18/graphlient/pull/79): Added client testing docs - [@GabrielDzul](https://github.com/GabrielDzul).
|
|
13
|
+
|
|
14
|
+
### 0.4.0 (2020/05/22)
|
|
15
|
+
|
|
16
|
+
* [#72](https://github.com/ashkan18/graphlient/pull/72): Add http_options - [@neroleung](https://github.com/neroleung).
|
|
17
|
+
* [#71](https://github.com/ashkan18/graphlient/issues/70): Add `Graphlient::Errors::TimeoutError` - [@BenDrozdoff](https://github.com/BenDrozdoff).
|
|
18
|
+
* [#75](https://github.com/ashkan18/graphlient/pull/75): Support Faraday 1.x - [@jfhinchcliffe](https://github.com/jfhinchcliffe).
|
|
19
|
+
* [#78](https://github.com/ashkan18/graphlient/pull/78): Add description of timeout values - [@sap1enza](https://github.com/sap1enza).
|
|
20
|
+
|
|
21
|
+
### 0.3.7 (2019/11/14)
|
|
3
22
|
|
|
4
|
-
### 0.3.7 (14/11/2019)
|
|
5
23
|
* [#68](https://github.com/ashkan18/graphlient/pull/68): Add `Graphlient::Errors::ConnectionFailedError` - [@neroleung](https://github.com/neroleung).
|
|
6
24
|
|
|
7
|
-
### 0.3.6 (07/23
|
|
25
|
+
### 0.3.6 (2019/07/23)
|
|
8
26
|
|
|
9
27
|
* [#63](https://github.com/ashkan18/graphlient/pull/63): Remove unused method for attribute with typo - [@ashkan18](https://github.com/ashkan18).
|
|
10
28
|
* [#62](https://github.com/ashkan18/graphlient/pull/62): Fix typo preventing access to response object on error - [@jmondo](https://github.com/jmondo).
|
|
11
29
|
|
|
12
|
-
### 0.3.4 (01/31
|
|
30
|
+
### 0.3.4 (2019/01/31)
|
|
13
31
|
|
|
14
32
|
* [#56](https://github.com/ashkan18/graphlient/pull/56): Remove safe navigation usage to retain support for Ruby 2.2 - [@avinoth](https://github.com/avinoth).
|
|
15
33
|
* [#57](https://github.com/ashkan18/graphlient/pull/57): Add support for parsing queries from a String - [@ateamlunchbox](https://github.com/ateamlunchbox).
|
|
16
34
|
|
|
17
|
-
### 0.3.3 (09/23
|
|
35
|
+
### 0.3.3 (2018/09/23)
|
|
18
36
|
|
|
19
37
|
* [#50](https://github.com/ashkan18/graphlient/pull/50): More detailed error responses - [@ashkan18](https://github.com/ashkan18).
|
|
20
38
|
|
|
21
|
-
### 0.3.2 (07/03
|
|
39
|
+
### 0.3.2 (2018/07/03)
|
|
22
40
|
|
|
23
41
|
* [#46](https://github.com/ashkan18/graphlient/pull/46): Fix issue with gathering error details when trying `to_s` on `GraphQLError` - [@ashkan18](https://github.com/ashkan18).
|
|
24
42
|
* [#45](https://github.com/ashkan18/graphlient/pull/45): Drop Support for Ruby 2.2 and Lock RuboCop - [@jonallured](https://github.com/jonallured).
|
|
25
43
|
|
|
26
|
-
### 0.3.1 (04/17
|
|
44
|
+
### 0.3.1 (2018/04/17)
|
|
27
45
|
|
|
28
46
|
* [#43](https://github.com/ashkan18/graphlient/pull/43): Allow to load and dump schema to json - [@povilasjurcys](https://github.com/povilasjurcys).
|
|
29
47
|
|
|
30
|
-
### 0.3.0 (02/22
|
|
48
|
+
### 0.3.0 (2018/02/22)
|
|
31
49
|
|
|
32
50
|
* [#38](https://github.com/ashkan18/graphlient/pull/38): Add support for Ruby 2.5 - [@yuki24](https://github.com/yuki24).
|
|
33
51
|
* [#39](https://github.com/ashkan18/graphlient/pull/39): Add support for Ruby 2.2 - [@yuki24](https://github.com/yuki24).
|
|
34
52
|
* [#40](https://github.com/ashkan18/graphlient/pull/40): Add experimental support for JRuby - [@yuki24](https://github.com/yuki24).
|
|
35
53
|
|
|
36
|
-
### 0.2.0 (11/09
|
|
54
|
+
### 0.2.0 (2017/11/09)
|
|
37
55
|
|
|
38
56
|
* [#33](https://github.com/ashkan18/graphlient/pull/33): Added dsl for supporting parametrized queries/mutations - [@ashkan18](https://github.com/ashkan18).
|
|
39
57
|
* [#34](https://github.com/ashkan18/graphlient/issues/34): Fix: don't convert variables to `String` - [@dblock](https://github.com/dblock).
|
|
40
58
|
|
|
41
|
-
### 0.1.0 (10/27
|
|
59
|
+
### 0.1.0 (2017/10/27)
|
|
42
60
|
|
|
43
61
|
* [#31](https://github.com/ashkan18/graphlient/issues/31): Fix: catch execution errors that don't contain field names - [@dblock](https://github.com/dblock).
|
|
44
62
|
|
|
45
|
-
### 0.0.9 (10/26
|
|
63
|
+
### 0.0.9 (2017/10/26)
|
|
46
64
|
|
|
47
65
|
* [#28](https://github.com/ashkan18/graphlient/pull/28): Raise errors in `execute`, not only `query` - [@dblock](https://github.com/dblock).
|
|
48
66
|
* [#29](https://github.com/ashkan18/graphlient/pull/29): Added `Graphlient::Adapters::HTTP::HTTPAdapter` that replaces Faraday with `Net::HTTP` - [@dblock](https://github.com/dblock).
|
|
49
67
|
|
|
50
|
-
### 0.0.8 (10/26
|
|
68
|
+
### 0.0.8 (2017/10/26)
|
|
51
69
|
|
|
52
70
|
* [#27](https://github.com/ashkan18/graphlient/pull/27): Always raise an exception unless a query has succeeded - [@dblock](https://github.com/dblock).
|
|
53
71
|
|
|
54
|
-
### 0.0.7 (10/24
|
|
72
|
+
### 0.0.7 (2017/10/24)
|
|
55
73
|
|
|
56
74
|
* [#26](https://github.com/ashkan18/graphlient/pull/26): Support String queries - [@dblock](https://github.com/dblock).
|
|
57
75
|
|
|
58
|
-
### 0.0.6 (10/20
|
|
76
|
+
### 0.0.6 (2017/10/20)
|
|
59
77
|
|
|
60
78
|
* [#14](https://github.com/ashkan18/graphlient/pull/14): Switch to `graphql-client` for network calls and schema validation - [@ashkan18](https://github.com/ashkan18).
|
|
61
79
|
* [#17](https://github.com/ashkan18/graphlient/pull/17): Specialize server errors as `Graphlient::Errors::Server` - [@dblock](https://github.com/dblock).
|
|
@@ -66,16 +84,16 @@
|
|
|
66
84
|
* [#20](https://github.com/ashkan18/graphlient/pull/20): Added support for parameterized queries and mutations - [@dblock](https://github.com/dblock).
|
|
67
85
|
* [#25](https://github.com/ashkan18/graphlient/pull/25): Added `client.parse` and `client.execute` to parse and execute queries separately - [@dblock](https://github.com/dblock).
|
|
68
86
|
|
|
69
|
-
### 0.0.5 (10/
|
|
87
|
+
### 0.0.5 (2017/10/05)
|
|
70
88
|
|
|
71
89
|
* [#11](https://github.com/ashkan18/graphlient/pull/11): Fixed query argument types - [@ashkan18](https://github.com/ashkan18).
|
|
72
90
|
|
|
73
|
-
### 0.0.4 (10/
|
|
91
|
+
### 0.0.4 (2017/10/04)
|
|
74
92
|
|
|
75
93
|
* [#8](https://github.com/ashkan18/graphlient/pull/8): Handle HTTP errors and raise `Graphlient::Errors::HTTP` on failure - [@dblock](https://github.com/dblock).
|
|
76
94
|
* [#5](https://github.com/ashkan18/graphlient/pull/5): Added RuboCop, Ruby-style linter, CHANGELOG, CONTRIBUTING and RELEASING - [@dblock](https://github.com/dblock).
|
|
77
95
|
* [#4](https://github.com/ashkan18/graphlient/pull/4): Refactored Graphlient::Client to take a URL and options, moved extensions - [@dblock](https://github.com/dblock).
|
|
78
96
|
|
|
79
|
-
### 0.0.3 (10/
|
|
97
|
+
### 0.0.3 (2017/10/03)
|
|
80
98
|
|
|
81
99
|
* Initial public release - [@ashkan18](https://github.com/ashkan18).
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Graphlient
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/graphlient)
|
|
4
|
-
[](https://github.com/ashkan18/graphlient/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
6
|
A friendlier Ruby client for consuming GraphQL-based APIs. Built on top of your usual [graphql-client](https://github.com/github/graphql-client), but with better defaults, more consistent error handling, and using the [faraday](https://github.com/lostisland/faraday) HTTP client.
|
|
7
7
|
|
|
@@ -15,16 +15,25 @@ 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
|
```
|
|
27
31
|
|
|
32
|
+
| http_options | default | type |
|
|
33
|
+
|---------------|---------|---------|
|
|
34
|
+
| read_timeout | nil | seconds |
|
|
35
|
+
| write_timeout | nil | seconds |
|
|
36
|
+
|
|
28
37
|
The schema is available automatically via `.schema`.
|
|
29
38
|
|
|
30
39
|
```ruby
|
|
@@ -127,6 +136,8 @@ Unlike graphql-client, Graphlient will always raise an exception unless the quer
|
|
|
127
136
|
* [Graphlient::Errors::FaradayServerError](lib/graphlient/errors/faraday_server_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
|
128
137
|
* [Graphlient::Errors::HttpServerError](lib/graphlient/errors/http_server_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
|
129
138
|
* [Graphlient::Errors::ConnectionFailedError](lib/graphlient/errors/connection_failed_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
|
139
|
+
* [Graphlient::Errors::TimeoutError](lib/graphlient/errors/timeout_error.rb): this inherits from `ServerError` ☝️, we recommend using `ServerError` to rescue these
|
|
140
|
+
* [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
141
|
|
|
131
142
|
|
|
132
143
|
All errors inherit from `Graphlient::Errors::Error` if you need to handle them in bulk.
|
|
@@ -334,7 +345,7 @@ describe App do
|
|
|
334
345
|
Graphlient::Client.new('http://test-graphql.biz/graphql') do |client|
|
|
335
346
|
client.http do |h|
|
|
336
347
|
h.connection do |c|
|
|
337
|
-
c.
|
|
348
|
+
c.adapter Faraday::Adapter::Rack, app
|
|
338
349
|
end
|
|
339
350
|
end
|
|
340
351
|
end
|
|
@@ -378,7 +389,49 @@ describe App do
|
|
|
378
389
|
end
|
|
379
390
|
```
|
|
380
391
|
|
|
392
|
+
In order to stub the response to actual queries, [dump the schema into a JSON file](#schema-storing-and-loading-on-disk) and specify it via schema_path as follows.
|
|
393
|
+
|
|
394
|
+
```ruby
|
|
395
|
+
describe App do
|
|
396
|
+
let(:url) { 'http://graph.biz/graphql' }
|
|
397
|
+
let(:client) { Graphlient::Client.new(url, schema_path: 'spec/support/fixtures/invoice_api.json') }
|
|
398
|
+
let(:query) do
|
|
399
|
+
<<~GRAPHQL
|
|
400
|
+
query{
|
|
401
|
+
invoice(id: 42) {
|
|
402
|
+
id
|
|
403
|
+
feeInCents
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
GRAPHQL
|
|
407
|
+
end
|
|
408
|
+
let(:json_response) do
|
|
409
|
+
{
|
|
410
|
+
'data' => {
|
|
411
|
+
'invoice' => {
|
|
412
|
+
'id' => '42',
|
|
413
|
+
'feeInCents' => 2000
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}.to_json
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
before do
|
|
420
|
+
stub_request(:post, url).to_return(
|
|
421
|
+
status: 200,
|
|
422
|
+
body: json_response
|
|
423
|
+
)
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
it 'returns invoice fees' do
|
|
427
|
+
response = client.query(query)
|
|
428
|
+
expect(response.data).to be_truthy
|
|
429
|
+
expect(response.data.invoice.id).to eq('42')
|
|
430
|
+
expect(response.data.invoice.fee_in_cents).to eq(2000)
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
```
|
|
434
|
+
|
|
381
435
|
## License
|
|
382
436
|
|
|
383
437
|
MIT License, see [LICENSE](LICENSE)
|
|
384
|
-
|
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
|
@@ -22,7 +22,7 @@ module Graphlient
|
|
|
22
22
|
query_params[:context] = @options if @options
|
|
23
23
|
query_params[:variables] = variables if variables
|
|
24
24
|
query = client.parse(query) if query.is_a?(String)
|
|
25
|
-
rc = client.query(query, query_params)
|
|
25
|
+
rc = client.query(query, **query_params)
|
|
26
26
|
raise Graphlient::Errors::GraphQLError, rc if rc.errors.any?
|
|
27
27
|
# see https://github.com/github/graphql-client/pull/132
|
|
28
28
|
# see https://github.com/exAspArk/graphql-errors/issues/2
|
|
@@ -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
|
|
@@ -65,7 +67,7 @@ module Graphlient
|
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
def errors_in_result?(response)
|
|
68
|
-
response.data && response.data.errors && response.data.errors.any?
|
|
70
|
+
response.data && response.data.errors && response.data.errors.all.any?
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
73
|
end
|
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,19 @@ 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|
|
|
108
|
+
expect(error.message).to include(error_message)
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
end
|
|
81
112
|
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
|