graphlient 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +10 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/README.md +4 -3
- data/graphlient.gemspec +1 -1
- data/lib/graphlient/adapters/http/faraday_adapter.rb +1 -1
- data/lib/graphlient/adapters/http/http_adapter.rb +1 -1
- data/lib/graphlient/client.rb +6 -3
- data/lib/graphlient/errors.rb +4 -3
- data/lib/graphlient/errors/{client.rb → client_error.rb} +1 -1
- data/lib/graphlient/errors/execution_error.rb +29 -0
- data/lib/graphlient/errors/{graphql.rb → graphql_error.rb} +1 -1
- data/lib/graphlient/errors/{server.rb → server_error.rb} +1 -1
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/client_query_spec.rb +13 -4
- data/spec/graphlient/client_schema_spec.rb +1 -1
- data/spec/support/dummy_app.rb +7 -13
- data/spec/support/dummy_schema.rb +8 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f73350b469913784302c46b7305cef2d8949ad32
|
4
|
+
data.tar.gz: 91e1a47a61c402174bef0f15a0568e05d26b73cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaadb8bf32399b399fae81c4ce62a3d73508317eb4a157f90c9bf1665a77f5d91116dc0e263a6d27a2d5dfad9eeca1ea730b3d81966d68d0519c65b2dd9cb3cc
|
7
|
+
data.tar.gz: f50b03492b2e1c82b974fd5e59952e00cd38f82e992d5a2be84efdb4afa146a4ec65cf3370b4d77054a9de3094b7fb483453aea6f48655695c73e76bbbd83d59
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2017-10-
|
3
|
+
# on 2017-10-27 10:35:56 -0400 using RuboCop version 0.47.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -13,6 +13,14 @@ Lint/UnusedMethodArgument:
|
|
13
13
|
Exclude:
|
14
14
|
- 'lib/graphlient/adapters/http/http_adapter.rb'
|
15
15
|
|
16
|
+
# Offense count: 1
|
17
|
+
Metrics/CyclomaticComplexity:
|
18
|
+
Max: 9
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
Metrics/PerceivedComplexity:
|
22
|
+
Max: 9
|
23
|
+
|
16
24
|
# Offense count: 1
|
17
25
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
18
26
|
# SupportedStyles: nested, compact
|
@@ -35,7 +43,7 @@ Style/MethodMissing:
|
|
35
43
|
- 'lib/graphlient/extensions/query.rb'
|
36
44
|
- 'lib/graphlient/query.rb'
|
37
45
|
|
38
|
-
# Offense count:
|
46
|
+
# Offense count: 4
|
39
47
|
Style/MultilineBlockChain:
|
40
48
|
Exclude:
|
41
49
|
- 'spec/graphlient/client_query_spec.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 0.1.0 (10/27/2017)
|
2
|
+
|
3
|
+
* [#31](https://github.com/ashkan18/graphlient/issues/31): Fix: catch execution errors that don't contain field names - [@dblock](https://github.com/dblock).
|
4
|
+
|
1
5
|
### 0.0.9 (10/26/2017)
|
2
6
|
|
3
7
|
* [#28](https://github.com/ashkan18/graphlient/pull/28): Raise errors in `execute`, not only `query` - [@dblock](https://github.com/dblock).
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -111,9 +111,10 @@ response.data.create_invoice.first.id
|
|
111
111
|
|
112
112
|
Unlike graphql-client, Graphlient will always raise an exception unless the query has succeeded.
|
113
113
|
|
114
|
-
* [Graphlient::Errors::
|
115
|
-
* [Graphlient::Errors::
|
116
|
-
* [Graphlient::Errors::
|
114
|
+
* [Graphlient::Errors::ClientError](lib/graphlient/errors/client_error.rb): all client-side query validation failures based on current schema
|
115
|
+
* [Graphlient::Errors::GraphQLError](lib/graphlient/errors/graphql_error.rb): all GraphQL API errors, with a humanly readable collection of problems
|
116
|
+
* [Graphlient::Errors::ExecutionError](lib/graphlient/errors/execution_error.rb): all GraphQL execution errors, with a humanly readable collection of problems
|
117
|
+
* [Graphlient::Errors::ServerError](lib/graphlient/errors/server_error.rb): all transport errors raised by Faraday
|
117
118
|
|
118
119
|
All errors inherit from `Graphlient::Errors::Error` if you need to handle them in bulk.
|
119
120
|
|
data/graphlient.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.require_paths = ['lib']
|
14
14
|
s.homepage = 'http://github.com/ashkan18/graphlient'
|
15
15
|
s.licenses = ['MIT']
|
16
|
-
s.summary = 'Ruby
|
16
|
+
s.summary = 'A friendlier Ruby client for consuming GraphQL-based APIs.'
|
17
17
|
s.add_dependency 'graphql-client'
|
18
18
|
s.add_dependency 'faraday'
|
19
19
|
s.add_dependency 'faraday_middleware'
|
@@ -20,7 +20,7 @@ module Graphlient
|
|
20
20
|
request.body = JSON.generate(body)
|
21
21
|
|
22
22
|
response = connection.request(request)
|
23
|
-
raise Graphlient::Errors::
|
23
|
+
raise Graphlient::Errors::ServerError.new("the server responded with status #{response.code}", response) unless response.is_a?(Net::HTTPOK)
|
24
24
|
JSON.parse(response.body)
|
25
25
|
end
|
26
26
|
|
data/lib/graphlient/client.rb
CHANGED
@@ -14,7 +14,7 @@ module Graphlient
|
|
14
14
|
end
|
15
15
|
client.parse(query_str.to_s)
|
16
16
|
rescue GraphQL::Client::Error => e
|
17
|
-
raise Graphlient::Errors::
|
17
|
+
raise Graphlient::Errors::ClientError.new(e.message, e)
|
18
18
|
end
|
19
19
|
|
20
20
|
def execute(query, variables = nil)
|
@@ -23,10 +23,13 @@ module Graphlient
|
|
23
23
|
query_params[:variables] = variables if variables
|
24
24
|
query = client.parse(query) if query.is_a?(String)
|
25
25
|
rc = client.query(query, query_params)
|
26
|
-
raise Graphlient::Errors::
|
26
|
+
raise Graphlient::Errors::GraphQLError, rc if rc.errors.any?
|
27
|
+
# see https://github.com/github/graphql-client/pull/132
|
28
|
+
# see https://github.com/exAspArk/graphql-errors/issues/2
|
29
|
+
raise Graphlient::Errors::ExecutionError, rc if rc.data && rc.data.errors && rc.data.errors.any?
|
27
30
|
rc
|
28
31
|
rescue GraphQL::Client::Error => e
|
29
|
-
raise Graphlient::Errors::
|
32
|
+
raise Graphlient::Errors::ClientError.new(e.message, e)
|
30
33
|
end
|
31
34
|
|
32
35
|
def query(query_or_variables = nil, variables = nil, &block)
|
data/lib/graphlient/errors.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'errors/error'
|
2
|
-
require_relative 'errors/
|
3
|
-
require_relative 'errors/
|
4
|
-
require_relative 'errors/
|
2
|
+
require_relative 'errors/client_error'
|
3
|
+
require_relative 'errors/server_error'
|
4
|
+
require_relative 'errors/graphql_error'
|
5
|
+
require_relative 'errors/execution_error'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Graphlient
|
2
|
+
module Errors
|
3
|
+
class ExecutionError < Error
|
4
|
+
attr_reader :response
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
super 'the server responded with a GraphQL execution error'
|
9
|
+
end
|
10
|
+
|
11
|
+
def errors
|
12
|
+
response.data.errors
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
errors.details.map do |key, details|
|
17
|
+
details = create_details(details).join("\n")
|
18
|
+
[key, details].compact.join(': ')
|
19
|
+
end.join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def create_details(details)
|
25
|
+
details.map { |detail| detail['message'] }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/graphlient/version.rb
CHANGED
@@ -79,10 +79,19 @@ describe Graphlient::Client do
|
|
79
79
|
it 'fails when wrong input type' do
|
80
80
|
expect do
|
81
81
|
client.execute(query, ids: ['42'])
|
82
|
-
end.to raise_error Graphlient::Errors::
|
82
|
+
end.to raise_error Graphlient::Errors::GraphQLError do |e|
|
83
83
|
expect(e.to_s).to eq "Variable ids of type [Int] was provided invalid value\n 0: Could not coerce value \"42\" to Int"
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
it 'fails on an execution error' do
|
88
|
+
expect do
|
89
|
+
allow(OpenStruct).to receive(:new).and_raise StandardError, 'Unexpected error.'
|
90
|
+
client.execute(query, ids: [42])
|
91
|
+
end.to raise_error Graphlient::Errors::ExecutionError do |e|
|
92
|
+
expect(e.to_s).to eq 'invoices: Unexpected error.'
|
93
|
+
end
|
94
|
+
end
|
86
95
|
end
|
87
96
|
end
|
88
97
|
|
@@ -98,7 +107,7 @@ describe Graphlient::Client do
|
|
98
107
|
end
|
99
108
|
end
|
100
109
|
end
|
101
|
-
end.to raise_error Graphlient::Errors::
|
110
|
+
end.to raise_error Graphlient::Errors::ClientError do |e|
|
102
111
|
expect(e.to_s).to eq "Field 'invoice' doesn't exist on type 'Query'"
|
103
112
|
end
|
104
113
|
end
|
@@ -160,7 +169,7 @@ describe Graphlient::Client do
|
|
160
169
|
end
|
161
170
|
end
|
162
171
|
end
|
163
|
-
end.to raise_error Graphlient::Errors::
|
172
|
+
end.to raise_error Graphlient::Errors::GraphQLError,
|
164
173
|
"Variable input of type createInvoiceInput! was provided invalid value\n : Expected value to not be null"
|
165
174
|
end
|
166
175
|
|
@@ -204,7 +213,7 @@ describe Graphlient::Client do
|
|
204
213
|
end
|
205
214
|
end
|
206
215
|
end
|
207
|
-
end.to raise_error Graphlient::Errors::
|
216
|
+
end.to raise_error Graphlient::Errors::GraphQLError,
|
208
217
|
"Variable input of type createInvoiceInput! was provided invalid value\n fee_in_cents: Expected value to not be null"
|
209
218
|
end
|
210
219
|
end
|
@@ -11,7 +11,7 @@ describe Graphlient::Client do
|
|
11
11
|
it 'fails with an exception' do
|
12
12
|
expect do
|
13
13
|
client.schema
|
14
|
-
end.to raise_error Graphlient::Errors::
|
14
|
+
end.to raise_error Graphlient::Errors::ServerError do |e|
|
15
15
|
expect(e.to_s).to eq 'the server responded with status 500'
|
16
16
|
end
|
17
17
|
end
|
data/spec/support/dummy_app.rb
CHANGED
@@ -9,17 +9,11 @@ before do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
post '/graphql' do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
).to_json
|
20
|
-
rescue StandardError => e
|
21
|
-
warn e
|
22
|
-
warn e.backtrace.join("\n")
|
23
|
-
raise e
|
24
|
-
end
|
12
|
+
headers['Content-Type'] = 'application/json'
|
13
|
+
DummySchema.execute(
|
14
|
+
params[:query],
|
15
|
+
variables: params[:variables] ? JSON.parse(params[:variables]) : {},
|
16
|
+
context: {},
|
17
|
+
operation_name: params[:operationName]
|
18
|
+
).to_json
|
25
19
|
end
|
@@ -3,7 +3,15 @@ require_relative 'types/invoice_type'
|
|
3
3
|
require_relative 'queries/query'
|
4
4
|
require_relative 'mutations/mutation'
|
5
5
|
|
6
|
+
require 'graphql/errors'
|
7
|
+
|
6
8
|
DummySchema = GraphQL::Schema.define do
|
7
9
|
query Query
|
8
10
|
mutation Mutation
|
9
11
|
end
|
12
|
+
|
13
|
+
GraphQL::Errors.configure(DummySchema) do
|
14
|
+
rescue_from StandardError do |e|
|
15
|
+
GraphQL::ExecutionError.new(e.message)
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphlient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
@@ -81,10 +81,11 @@ files:
|
|
81
81
|
- lib/graphlient/adapters/http/http_adapter.rb
|
82
82
|
- lib/graphlient/client.rb
|
83
83
|
- lib/graphlient/errors.rb
|
84
|
-
- lib/graphlient/errors/
|
84
|
+
- lib/graphlient/errors/client_error.rb
|
85
85
|
- lib/graphlient/errors/error.rb
|
86
|
-
- lib/graphlient/errors/
|
87
|
-
- lib/graphlient/errors/
|
86
|
+
- lib/graphlient/errors/execution_error.rb
|
87
|
+
- lib/graphlient/errors/graphql_error.rb
|
88
|
+
- lib/graphlient/errors/server_error.rb
|
88
89
|
- lib/graphlient/extensions.rb
|
89
90
|
- lib/graphlient/extensions/query.rb
|
90
91
|
- lib/graphlient/query.rb
|
@@ -124,8 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
125
|
version: 1.3.6
|
125
126
|
requirements: []
|
126
127
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.5.1
|
128
129
|
signing_key:
|
129
130
|
specification_version: 4
|
130
|
-
summary: Ruby
|
131
|
+
summary: A friendlier Ruby client for consuming GraphQL-based APIs.
|
131
132
|
test_files: []
|