Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix faraday use / adapter error #75

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion graphlient.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion lib/graphlient/adapters/http/faraday_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/graphlient/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Graphlient
VERSION = '0.3.7'.freeze
VERSION = '0.4.0'.freeze
end
6 changes: 3 additions & 3 deletions spec/graphlient/adapters/http/faraday_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/graphlient/client_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/graphlient/static_client_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/context/dummy_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down