graphlient 0.0.7 → 0.0.8
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/.rubocop_todo.yml +13 -4
- data/CHANGELOG.md +4 -0
- data/README.md +11 -3
- data/lib/graphlient/client.rb +6 -4
- data/lib/graphlient/errors.rb +1 -0
- data/lib/graphlient/errors/graphql.rb +44 -0
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/client_query_spec.rb +23 -12
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da18e4b9370c65fb4e6add0b644c89b55149b32
|
4
|
+
data.tar.gz: 39a55d067517d0be0f609ea3fcea3836cc0c4e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d443d7ca4023923bce79d474e59bab4e7f85fb2b4f270fd8466435997c89dfb8bb763821728b428d7e8dde0f196b4f2e4ae8e9747c805e11dbae301707b7326f
|
7
|
+
data.tar.gz: 3bf4e9568f17b0a26566a1d79f422395ce545a6273ca37c8d177a858734e78dcee1d3a5706678e0613998a67d63d7b309dec0be14b9edef0342759b9943d5917
|
data/.rubocop_todo.yml
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2017-10-
|
3
|
+
# on 2017-10-25 13:18:43 -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
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 1
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
|
12
|
+
# SupportedStylesAlignWith: keyword, variable, start_of_line
|
13
|
+
Lint/EndAlignment:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/graphlient/client.rb'
|
16
|
+
|
9
17
|
# Offense count: 11
|
10
18
|
# Configuration parameters: CountComments, ExcludedMethods.
|
11
19
|
Metrics/BlockLength:
|
12
|
-
Max:
|
20
|
+
Max: 178
|
13
21
|
|
14
|
-
# Offense count:
|
22
|
+
# Offense count: 19
|
15
23
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
16
24
|
# URISchemes: http, https
|
17
25
|
Metrics/LineLength:
|
@@ -29,7 +37,7 @@ Style/ClassAndModuleChildren:
|
|
29
37
|
Exclude:
|
30
38
|
- 'spec/graphlient/static_client_query_spec.rb'
|
31
39
|
|
32
|
-
# Offense count:
|
40
|
+
# Offense count: 6
|
33
41
|
Style/Documentation:
|
34
42
|
Exclude:
|
35
43
|
- 'spec/**/*'
|
@@ -37,6 +45,7 @@ Style/Documentation:
|
|
37
45
|
- 'lib/graphlient/adapters/faraday_adapter.rb'
|
38
46
|
- 'lib/graphlient/client.rb'
|
39
47
|
- 'lib/graphlient/errors/error.rb'
|
48
|
+
- 'lib/graphlient/errors/graphql.rb'
|
40
49
|
- 'lib/graphlient/extensions/query.rb'
|
41
50
|
- 'lib/graphlient/query.rb'
|
42
51
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 0.0.8 (10/26/2017)
|
2
|
+
|
3
|
+
* [#27](https://github.com/ashkan18/graphlient/pull/27): Always raise an exception unless a query has succeeded - [@dblock](https://github.com/dblock).
|
4
|
+
|
1
5
|
### 0.0.7 (10/24/2017)
|
2
6
|
|
3
7
|
* [#26](https://github.com/ashkan18/graphlient/pull/26): Support String queries - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](https://badge.fury.io/rb/graphlient)
|
4
4
|
[](https://travis-ci.org/ashkan18/graphlient)
|
5
5
|
|
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, and using the [faraday](https://github.com/lostisland/faraday) HTTP client.
|
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
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -82,8 +82,6 @@ query {
|
|
82
82
|
}
|
83
83
|
```
|
84
84
|
|
85
|
-
Graphlient validates the query based on current schema. In case of validation errors or any other connection related issues you'll get `Graphlient::Errors::Client` describing the error and in case of transport errors, `Graphlient::Errors::Server`. Both inherit from `Graphlient::Errors::Error` if you need to handle them in bulk.
|
86
|
-
|
87
85
|
A successful response object always contains data which can be iterated upon. The following example returns the first line item's price.
|
88
86
|
|
89
87
|
```ruby
|
@@ -109,6 +107,16 @@ The successful response contains data in `response.data`. The following example
|
|
109
107
|
response.data.create_invoice.first.id
|
110
108
|
```
|
111
109
|
|
110
|
+
### Error Handling
|
111
|
+
|
112
|
+
Unlike graphql-client, Graphlient will always raise an exception unless the query has succeeded.
|
113
|
+
|
114
|
+
* [Graphlient::Errors::Client](lib/graphlient/errors/client.rb): all client-side query validation failures based on current schema
|
115
|
+
* [Graphlient::Errors::GraphQL](lib/graphlient/errors/graphql.rb): all GraphQL API errors, with a humanly readable collection of problems
|
116
|
+
* [Graphlient::Errors::Server](lib/graphlient/errors/server.rb): all transport errors raised by Faraday
|
117
|
+
|
118
|
+
All errors inherit from `Graphlient::Errors::Error` if you need to handle them in bulk.
|
119
|
+
|
112
120
|
### Executing Parameterized Queries and Mutations
|
113
121
|
|
114
122
|
Graphlient can execute parameterized queries and mutations by providing variables as query parameters.
|
data/lib/graphlient/client.rb
CHANGED
@@ -29,11 +29,13 @@ module Graphlient
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def query(query_or_variables = nil, variables = nil, &block)
|
32
|
-
if block_given?
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
rc = if block_given?
|
33
|
+
execute(parse(&block), query_or_variables)
|
34
|
+
else
|
35
|
+
execute(query_or_variables, variables)
|
36
36
|
end
|
37
|
+
raise Graphlient::Errors::GraphQL, rc if rc.errors.any?
|
38
|
+
rc
|
37
39
|
rescue GraphQL::Client::Error => e
|
38
40
|
raise Graphlient::Errors::Client.new(e.message, e)
|
39
41
|
end
|
data/lib/graphlient/errors.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Graphlient
|
2
|
+
module Errors
|
3
|
+
class GraphQL < Error
|
4
|
+
attr_reader :response
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
super 'the server responded with a GraphQL error'
|
9
|
+
end
|
10
|
+
|
11
|
+
def errors
|
12
|
+
response.errors
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
errors.details.map do |key, details|
|
17
|
+
details = create_details(details).join("\n")
|
18
|
+
[key == 'data' ? nil : key, details].compact.join(': ')
|
19
|
+
end.join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def create_details(details)
|
25
|
+
details.map { |detail| create_detail(detail) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_detail(detail)
|
29
|
+
message = detail['message']
|
30
|
+
[message, create_problems(detail['problems']).compact.join("\n ")].join("\n ")
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_problems(problems)
|
34
|
+
problems.map { |problem| create_problem(problem) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_problem(problem)
|
38
|
+
paths = problem['path'].join(', ')
|
39
|
+
explanation = problem['explanation']
|
40
|
+
[paths, explanation].join(': ')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/graphlient/version.rb
CHANGED
@@ -143,20 +143,17 @@ describe Graphlient::Client do
|
|
143
143
|
|
144
144
|
context 'parameterized query' do
|
145
145
|
it 'fails when missing input' do
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
expect do
|
147
|
+
client.query do
|
148
|
+
mutation('$input' => :createInvoiceInput!) do
|
149
|
+
createInvoice(input: :$input) do
|
150
|
+
id
|
151
|
+
fee_in_cents
|
152
|
+
end
|
151
153
|
end
|
152
154
|
end
|
153
|
-
end
|
154
|
-
|
155
|
-
expect(response.errors.messages['data']).to eq(
|
156
|
-
[
|
157
|
-
'Variable input of type createInvoiceInput! was provided invalid value'
|
158
|
-
]
|
159
|
-
)
|
155
|
+
end.to raise_error Graphlient::Errors::GraphQL,
|
156
|
+
"Variable input of type createInvoiceInput! was provided invalid value\n : Expected value to not be null"
|
160
157
|
end
|
161
158
|
|
162
159
|
it 'returns a response from a query' do
|
@@ -188,6 +185,20 @@ describe Graphlient::Client do
|
|
188
185
|
expect(invoice.id).to eq 1231
|
189
186
|
expect(invoice.fee_in_cents).to eq 12_345
|
190
187
|
end
|
188
|
+
|
189
|
+
it 'fails when mutation missing a field' do
|
190
|
+
expect do
|
191
|
+
client.query(input: {}) do
|
192
|
+
mutation(:$input => :createInvoiceInput!) do
|
193
|
+
createInvoice(input: :$input) do
|
194
|
+
id
|
195
|
+
fee_in_cents
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end.to raise_error Graphlient::Errors::GraphQL,
|
200
|
+
"Variable input of type createInvoiceInput! was provided invalid value\n fee_in_cents: Expected value to not be null"
|
201
|
+
end
|
191
202
|
end
|
192
203
|
end
|
193
204
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphlient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql-client
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/graphlient/errors.rb
|
80
80
|
- lib/graphlient/errors/client.rb
|
81
81
|
- lib/graphlient/errors/error.rb
|
82
|
+
- lib/graphlient/errors/graphql.rb
|
82
83
|
- lib/graphlient/errors/server.rb
|
83
84
|
- lib/graphlient/extensions.rb
|
84
85
|
- lib/graphlient/extensions/query.rb
|