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..8e28cbc 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,17 @@ Upgrading Graphlient =========================== +### 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/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..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 @@ -34,7 +36,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..060170f 100644 --- a/lib/graphlient/version.rb +++ b/lib/graphlient/version.rb @@ -1,3 +1,3 @@ module Graphlient - VERSION = '0.3.7'.freeze + VERSION = '0.4.0'.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/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 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