graphlient 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +9 -1
- data/README.md +17 -0
- data/RELEASING.md +2 -0
- data/lib/graphlient/adapters/http/http_adapter.rb +1 -1
- data/lib/graphlient/client.rb +7 -3
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/static_client_query_spec.rb +35 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6d0e92ac6d77cf9f1e57056c517074fb3ddf053
|
4
|
+
data.tar.gz: b9ecc89c535d2ef16ca945df3836a499038279ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4295209e08e772f6d3e419d38df7f6eda09d02c47f84f97ec4b2f1ae13b7c716013a43715d336830f80bf7309d0d0a8eb67151d3162118c5a716dbef948abd49
|
7
|
+
data.tar.gz: 5cbb4cc4fae863e5bb91257d8299249709e06b3b6a0c8fcb9d29aa7f5db90219df977c11417338ac7af9778fbcb66dbaa673c1af438b62daf51f77744dd138d2
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
### 0.3.
|
1
|
+
### 0.3.5 (Next)
|
2
2
|
|
3
3
|
* Your contribution here.
|
4
|
+
|
5
|
+
### 0.3.4 (01/31/2019)
|
6
|
+
|
7
|
+
* [#56](https://github.com/ashkan18/graphlient/pull/56): Remove safe navigation usage to retain support for Ruby 2.2 - [@avinoth](https://github.com/avinoth).
|
8
|
+
* [#57](https://github.com/ashkan18/graphlient/pull/57): Add support for parsing queries from a String - [@ateamlunchbox](https://github.com/ateamlunchbox).
|
9
|
+
|
10
|
+
### 0.3.3 (09/23/2018)
|
11
|
+
|
4
12
|
* [#50](https://github.com/ashkan18/graphlient/pull/50): More detailed error responses - [@ashkan18](https://github.com/ashkan18).
|
5
13
|
|
6
14
|
### 0.3.2 (07/03/2018)
|
data/README.md
CHANGED
@@ -208,6 +208,23 @@ end
|
|
208
208
|
client.execute query, ids: [42]
|
209
209
|
```
|
210
210
|
|
211
|
+
Or pass in a string instead of a block:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
# parse a query, returns a GraphQL::Client::OperationDefinition
|
215
|
+
query = client.parse <<~GRAPHQL
|
216
|
+
query($some_id: Int) {
|
217
|
+
invoice(id: $some_id) {
|
218
|
+
id
|
219
|
+
feeInCents
|
220
|
+
}
|
221
|
+
}
|
222
|
+
GRAPHQL
|
223
|
+
|
224
|
+
# execute a query, returns a GraphQL::Client::Response
|
225
|
+
client.execute query, ids: [42]
|
226
|
+
```
|
227
|
+
|
211
228
|
### Dynamic vs. Static Queries
|
212
229
|
|
213
230
|
Graphlient uses [graphql-client](https://github.com/github/graphql-client), which [recommends](https://github.com/github/graphql-client/blob/master/guides/dynamic-query-error.md) building queries as static module members along with dynamic variables during execution. This can be accomplished with graphlient the same way.
|
data/RELEASING.md
CHANGED
@@ -21,6 +21,8 @@ Change next release in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
|
21
21
|
|
22
22
|
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
23
23
|
|
24
|
+
Update the version in `lib/graphlient/version.rb`.
|
25
|
+
|
24
26
|
Commit your changes.
|
25
27
|
|
26
28
|
```
|
@@ -9,7 +9,7 @@ module Graphlient
|
|
9
9
|
|
10
10
|
request['Accept'] = 'application/json'
|
11
11
|
request['Content-Type'] = 'application/json'
|
12
|
-
headers
|
12
|
+
headers && headers.each { |name, value| request[name] = value }
|
13
13
|
|
14
14
|
body = {}
|
15
15
|
body['query'] = document.to_query_string
|
data/lib/graphlient/client.rb
CHANGED
@@ -8,8 +8,8 @@ module Graphlient
|
|
8
8
|
yield self if block_given?
|
9
9
|
end
|
10
10
|
|
11
|
-
def parse(&block)
|
12
|
-
query_str
|
11
|
+
def parse(query_str = nil, &block)
|
12
|
+
query_str ||= Graphlient::Query.new do
|
13
13
|
instance_eval(&block)
|
14
14
|
end
|
15
15
|
client.parse(query_str.to_s)
|
@@ -26,7 +26,7 @@ module Graphlient
|
|
26
26
|
raise Graphlient::Errors::GraphQLError, rc if rc.errors.any?
|
27
27
|
# see https://github.com/github/graphql-client/pull/132
|
28
28
|
# see https://github.com/exAspArk/graphql-errors/issues/2
|
29
|
-
raise Graphlient::Errors::ExecutionError, rc if rc
|
29
|
+
raise Graphlient::Errors::ExecutionError, rc if errors_in_result?(rc)
|
30
30
|
rc
|
31
31
|
rescue GraphQL::Client::Error => e
|
32
32
|
raise Graphlient::Errors::ClientError, e.message
|
@@ -63,5 +63,9 @@ module Graphlient
|
|
63
63
|
client.allow_dynamic_queries = @options.key?(:allow_dynamic_queries) ? options[:allow_dynamic_queries] : true
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
def errors_in_result?(response)
|
68
|
+
response.data && response.data.errors && response.data.errors.any?
|
69
|
+
end
|
66
70
|
end
|
67
71
|
end
|
data/lib/graphlient/version.rb
CHANGED
@@ -15,7 +15,16 @@ describe Graphlient::Client do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
StringQuery = Client.parse <<~GRAPHQL
|
19
|
+
query($some_id: Int) {
|
20
|
+
invoice(id: $some_id) {
|
21
|
+
id
|
22
|
+
feeInCents
|
23
|
+
}
|
24
|
+
}
|
25
|
+
GRAPHQL
|
26
|
+
|
27
|
+
BlockQuery = Client.parse do
|
19
28
|
query(some_id: :int) do
|
20
29
|
invoice(id: :some_id) do
|
21
30
|
id
|
@@ -29,11 +38,31 @@ describe Graphlient::Client do
|
|
29
38
|
expect(Graphlient::Client::Spec::Client.send(:client).allow_dynamic_queries).to be false
|
30
39
|
end
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
context 'with string-based queries' do
|
42
|
+
it 'parses a string query to an OperationDefinition' do
|
43
|
+
expect(Graphlient::Client::Spec::StringQuery.class).to be GraphQL::Client::OperationDefinition
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'sets the OperationDefinition that came from a string to have a name' do
|
47
|
+
expect(Graphlient::Client::Spec::StringQuery.definition_name).to eql 'Graphlient__Client__Spec__StringQuery'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with both string- and block-based queries' do
|
52
|
+
it 'gets identical results parsing equivalent string- and block-based queries' do
|
53
|
+
block_response = Graphlient::Client::Spec::Client.execute(Graphlient::Client::Spec::BlockQuery, some_id: 42)
|
54
|
+
string_response = Graphlient::Client::Spec::Client.execute(Graphlient::Client::Spec::StringQuery, some_id: 42)
|
55
|
+
expect(string_response.to_h).to eq block_response.to_h
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'executing a query' do
|
60
|
+
it 'succeeds with expected feeInCents' do
|
61
|
+
response = Graphlient::Client::Spec::Client.execute(Graphlient::Client::Spec::BlockQuery, some_id: 42)
|
62
|
+
invoice = response.data.invoice
|
63
|
+
expect(invoice.id).to eq '42'
|
64
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
65
|
+
end
|
37
66
|
end
|
38
67
|
end
|
39
68
|
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.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: 1.3.6
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.4.8
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: A friendlier Ruby client for consuming GraphQL-based APIs.
|