From 8eff8386aaff95167a704a5dc010a3fcb47b2bfc Mon Sep 17 00:00:00 2001 From: Jason Hinchcliffe Date: Mon, 4 May 2020 08:29:53 +1000 Subject: [PATCH 1/2] fix: use .adapter rather than .use for Faraday --- CHANGELOG.md | 3 ++- README.md | 2 +- UPGRADING.md | 6 ++++++ graphlient.gemspec | 2 +- lib/graphlient/adapters/http/faraday_adapter.rb | 2 +- lib/graphlient/version.rb | 2 +- spec/graphlient/adapters/http/faraday_adapter_spec.rb | 6 +++--- spec/graphlient/static_client_query_spec.rb | 2 +- spec/support/context/dummy_client.rb | 2 +- 9 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 328cb3c..e5cb42f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ -### 0.3.8 (Next) +### 0.4.0 (Next) * [#72](https://github.com/ashkan18/graphlient/pull/72): Add http_options - [@neroleung](https://github.com/neroleung). * [#71](https://github.com/ashkan18/graphlient/issues/70): Add `Graphlient::Errors::TimeoutError` - [@BenDrozdoff](https://github.com/BenDrozdoff). +* [#75](https://github.com/ashkan18/graphlient/pull/75): Support Faraday 1.x - [@jfhinchcliffe](https://github.com/jfhinchcliffe). * Your contribution here. ### 0.3.7 (14/11/2019) diff --git a/README.md b/README.md index 3bde27d..618b5cf 100644 --- a/README.md +++ b/README.md @@ -340,7 +340,7 @@ describe App do Graphlient::Client.new('http://test-graphql.biz/graphql') do |client| client.http do |h| h.connection do |c| - c.use Faraday::Adapter::Rack, app + c.adapter Faraday::Adapter::Rack, app end end end diff --git a/UPGRADING.md b/UPGRADING.md index 3ab05a8..7110138 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,12 @@ Upgrading Graphlient =========================== +### Upgrading to >= 0.3.8 + +#### Requires Faraday >= 1.0 + +See [#75](https://github.com/ashkan18/graphlient/pull/75). + ### Upgrading to >= 0.3.7 #### Changes in error handling of connection refused error diff --git a/graphlient.gemspec b/graphlient.gemspec index 81536cb..d9725f8 100644 --- a/graphlient.gemspec +++ b/graphlient.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.homepage = 'http://github.com/ashkan18/graphlient' s.licenses = ['MIT'] s.summary = 'A friendlier Ruby client for consuming GraphQL-based APIs.' - s.add_dependency 'faraday' + s.add_dependency 'faraday', '>= 1.0' s.add_dependency 'faraday_middleware' s.add_dependency 'graphql-client' end diff --git a/lib/graphlient/adapters/http/faraday_adapter.rb b/lib/graphlient/adapters/http/faraday_adapter.rb index dccca3e..9ffd1d1 100644 --- a/lib/graphlient/adapters/http/faraday_adapter.rb +++ b/lib/graphlient/adapters/http/faraday_adapter.rb @@ -34,7 +34,7 @@ def connection if block_given? yield c else - c.use Faraday::Adapter::NetHttp + c.adapter Faraday::Adapter::NetHttp end end end diff --git a/lib/graphlient/version.rb b/lib/graphlient/version.rb index 75867db..6134f25 100644 --- a/lib/graphlient/version.rb +++ b/lib/graphlient/version.rb @@ -1,3 +1,3 @@ module Graphlient - VERSION = '0.3.7'.freeze + VERSION = '0.3.8'.freeze end diff --git a/spec/graphlient/adapters/http/faraday_adapter_spec.rb b/spec/graphlient/adapters/http/faraday_adapter_spec.rb index 1639cfb..910eb8d 100644 --- a/spec/graphlient/adapters/http/faraday_adapter_spec.rb +++ b/spec/graphlient/adapters/http/faraday_adapter_spec.rb @@ -8,19 +8,19 @@ Graphlient::Client.new('http://example.com/graphql') do |client| client.http do |h| h.connection do |c| - c.use Faraday::Adapter::Rack, app + c.adapter Faraday::Adapter::Rack, app end end end end it 'inserts a middleware into the connection' do + expect(client.http.connection.adapter).to eq Faraday::Adapter::Rack expect(client.http.connection.builder.handlers).to eq( [ Faraday::Response::RaiseError, FaradayMiddleware::EncodeJson, - FaradayMiddleware::ParseJson, - Faraday::Adapter::Rack + FaradayMiddleware::ParseJson ] ) end diff --git a/spec/graphlient/static_client_query_spec.rb b/spec/graphlient/static_client_query_spec.rb index 3c7b8e6..5a47e46 100644 --- a/spec/graphlient/static_client_query_spec.rb +++ b/spec/graphlient/static_client_query_spec.rb @@ -10,7 +10,7 @@ module Graphlient::Client::Spec ) do |client| client.http do |h| h.connection do |c| - c.use Faraday::Adapter::Rack, Sinatra::Application + c.adapter Faraday::Adapter::Rack, Sinatra::Application end end end diff --git a/spec/support/context/dummy_client.rb b/spec/support/context/dummy_client.rb index ee917df..4101bff 100644 --- a/spec/support/context/dummy_client.rb +++ b/spec/support/context/dummy_client.rb @@ -18,7 +18,7 @@ def app Graphlient::Client.new(endpoint, headers: headers) do |client| client.http do |h| h.connection do |c| - c.use Faraday::Adapter::Rack, app + c.adapter Faraday::Adapter::Rack, app end end end From 8c051a0f5820663efb5bd4c7406266e626dabe1e Mon Sep 17 00:00:00 2001 From: Jason Hinchcliffe Date: Mon, 4 May 2020 09:06:00 +1000 Subject: [PATCH 2/2] fix: rescue Faraday error --- UPGRADING.md | 7 ++++++- lib/graphlient/adapters/http/faraday_adapter.rb | 2 ++ lib/graphlient/version.rb | 2 +- spec/graphlient/client_schema_spec.rb | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 7110138..8e28cbc 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,12 +1,17 @@ Upgrading Graphlient =========================== -### Upgrading to >= 0.3.8 +### Upgrading to >= 0.4.0 #### Requires Faraday >= 1.0 See [#75](https://github.com/ashkan18/graphlient/pull/75). +#### Changes in error handling of connection refused error + +When the GraphQL request was failing, we were receiving a `Faraday::ServerError`. After 0.4.0, Graphlient +will return `Graphlient::Errors::FaradayServerError` instead. + ### Upgrading to >= 0.3.7 #### Changes in error handling of connection refused error diff --git a/lib/graphlient/adapters/http/faraday_adapter.rb b/lib/graphlient/adapters/http/faraday_adapter.rb index 9ffd1d1..601dcae 100644 --- a/lib/graphlient/adapters/http/faraday_adapter.rb +++ b/lib/graphlient/adapters/http/faraday_adapter.rb @@ -21,6 +21,8 @@ def execute(document:, operation_name:, variables:, context:) raise Graphlient::Errors::TimeoutError, e rescue Faraday::ClientError => e raise Graphlient::Errors::FaradayServerError, e + rescue Faraday::ServerError => e + raise Graphlient::Errors::FaradayServerError, e end def connection diff --git a/lib/graphlient/version.rb b/lib/graphlient/version.rb index 6134f25..060170f 100644 --- a/lib/graphlient/version.rb +++ b/lib/graphlient/version.rb @@ -1,3 +1,3 @@ module Graphlient - VERSION = '0.3.8'.freeze + VERSION = '0.4.0'.freeze end diff --git a/spec/graphlient/client_schema_spec.rb b/spec/graphlient/client_schema_spec.rb index 6316337..73b1150 100644 --- a/spec/graphlient/client_schema_spec.rb +++ b/spec/graphlient/client_schema_spec.rb @@ -19,7 +19,7 @@ it 'fails with an exception' do expect do client.schema - end.to raise_error Graphlient::Errors::ServerError do |e| + end.to raise_error Graphlient::Errors::FaradayServerError do |e| expect(e.to_s).to eq 'the server responded with status 500' expect(e.status_code).to eq 500 expect(e.response['errors'].size).to eq 1