graphql_client 0.3.3 → 0.4.1
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/CHANGELOG.md +4 -0
- data/README.md +14 -0
- data/graphql_ruby_client.gemspec +1 -1
- data/lib/graphql_client/base.rb +5 -1
- data/lib/graphql_client/response.rb +1 -1
- data/lib/graphql_client/version.rb +1 -1
- data/test/graphql_client/http_client_test.rb +37 -0
- data/test/graphql_client/response_object_test.rb +6 -0
- data/test/graphql_client/response_test.rb +4 -6
- metadata +3 -4
- data/shipit.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef03a205ab7279feb064cf18c8155e51bcec815d
|
4
|
+
data.tar.gz: 37dd8c3bf4cff061652a9695aece60c98cc8d30b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b39ab7a0b9a8f66fe8f784404e58c65421e73366027acb8672a75af1a13ccf579ad1d580aeb574d2472d0889ca970d375a85a2a0a7a79cac73387bf55d3cf86
|
7
|
+
data.tar.gz: '093ddc0a6dd2e375ff7beb410dc46dbf6b47d48f24329558276d468ebd179f31dc4da3c93da381b22108708bd9ece30620c6a59161cda15a1818324c8f79538a'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -94,3 +94,17 @@ response = client.raw_query('
|
|
94
94
|
|
95
95
|
puts response.shop.name
|
96
96
|
```
|
97
|
+
|
98
|
+
### Extensions
|
99
|
+
|
100
|
+
The GraphQL specification allows for an [`extensions` key](http://facebook.github.io/graphql/October2016/#sec-Response-Format) in the response. To access this data use the `raw_query_with_extensions` method instead. It will return a tuple of response objects, one for the `data` key and one for the `extensions` key.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
data, extensions = client.raw_query_with_extensions('
|
104
|
+
query {
|
105
|
+
shop {
|
106
|
+
name
|
107
|
+
}
|
108
|
+
}
|
109
|
+
')
|
110
|
+
```
|
data/graphql_ruby_client.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = ''
|
13
13
|
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
14
14
|
s.version = GraphQL::Client::VERSION
|
15
|
-
s.executables
|
15
|
+
s.executables = 'graphql-client'
|
16
16
|
|
17
17
|
s.add_runtime_dependency 'graphql_schema', '~> 0.1.5'
|
18
18
|
|
data/lib/graphql_client/base.rb
CHANGED
@@ -33,8 +33,12 @@ module GraphQL
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def raw_query(query_string, operation_name: nil, variables: {})
|
36
|
+
raw_query_with_extensions(query_string, operation_name: operation_name, variables: variables)[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
def raw_query_with_extensions(query_string, operation_name: nil, variables: {})
|
36
40
|
response = adapter.request(query_string, operation_name: operation_name, variables: variables)
|
37
|
-
ResponseObject.new(response.data)
|
41
|
+
[ResponseObject.new(response.data), ResponseObject.new(response.extensions)]
|
38
42
|
end
|
39
43
|
|
40
44
|
private
|
@@ -47,6 +47,43 @@ module GraphQL
|
|
47
47
|
|
48
48
|
adapter.verify
|
49
49
|
end
|
50
|
+
|
51
|
+
def test_raw_query_with_extensions_calls_adapter_request_with_query_string
|
52
|
+
config = Config.new(url: 'http://example.com')
|
53
|
+
|
54
|
+
adapter = Minitest::Mock.new
|
55
|
+
adapter.expect(:request, Response.new('{}'), ['query { shop }', operation_name: nil, variables: {}])
|
56
|
+
|
57
|
+
client = Base.new(schema_fixture('schema.json'), config: config, adapter: adapter)
|
58
|
+
client.raw_query_with_extensions('query { shop }')
|
59
|
+
|
60
|
+
adapter.verify
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_raw_query_with_extensions_returns_response_objects_for_data_and_extensions
|
64
|
+
config = Config.new(url: 'http://example.com')
|
65
|
+
|
66
|
+
response = Minitest::Mock.new
|
67
|
+
response.expect(:data, { 'name' => 'shop' })
|
68
|
+
response.expect(:extensions, { 'foo' => 'bar' })
|
69
|
+
|
70
|
+
client = Base.new(schema_fixture('schema.json'), config: config, adapter: AdapterStub.new(response))
|
71
|
+
data, extensions = client.raw_query_with_extensions('query { shop }')
|
72
|
+
|
73
|
+
assert_equal 'shop', data.name
|
74
|
+
assert_equal 'bar', extensions.foo
|
75
|
+
response.verify
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class AdapterStub
|
80
|
+
def initialize(request)
|
81
|
+
@request = request
|
82
|
+
end
|
83
|
+
|
84
|
+
def request(*)
|
85
|
+
@request
|
86
|
+
end
|
50
87
|
end
|
51
88
|
end
|
52
89
|
end
|
@@ -3,6 +3,12 @@ require 'test_helper'
|
|
3
3
|
module GraphQL
|
4
4
|
module Client
|
5
5
|
class ResponseObjectTest < Minitest::Test
|
6
|
+
def test_builds_response_objects_from_nil
|
7
|
+
result = ResponseObject.new(nil)
|
8
|
+
|
9
|
+
assert_equal({}, result.data)
|
10
|
+
end
|
11
|
+
|
6
12
|
def test_builds_response_objects_from_hashes
|
7
13
|
result = ResponseObject.new(
|
8
14
|
'myshop' => {
|
@@ -34,21 +34,19 @@ module GraphQL
|
|
34
34
|
def test_initialize_sets_extensions
|
35
35
|
body = {
|
36
36
|
data: { id: 1 },
|
37
|
-
extensions:
|
38
|
-
{ foo: 'bar' }
|
39
|
-
]
|
37
|
+
extensions: { foo: 'bar' }
|
40
38
|
}
|
41
39
|
|
42
40
|
response = Response.new(body.to_json)
|
43
41
|
|
44
|
-
assert_equal
|
42
|
+
assert_equal({ 'foo' => 'bar' }, response.extensions)
|
45
43
|
end
|
46
44
|
|
47
|
-
def
|
45
|
+
def test_initialize_with_no_extensions_sets_it_to_nil
|
48
46
|
body = { data: { id: 1 } }
|
49
47
|
response = Response.new(body.to_json)
|
50
48
|
|
51
|
-
|
49
|
+
assert_nil response.extensions
|
52
50
|
end
|
53
51
|
|
54
52
|
def test_initialize_raises_error_if_response_contains_errors_without_data
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql_schema
|
@@ -175,7 +175,6 @@ files:
|
|
175
175
|
- lib/graphql_client/schema_patches.rb
|
176
176
|
- lib/graphql_client/version.rb
|
177
177
|
- shipit.rubygems.yml
|
178
|
-
- shipit.yml
|
179
178
|
- test/graphql_client/adapters/http_adapter_test.rb
|
180
179
|
- test/graphql_client/config_test.rb
|
181
180
|
- test/graphql_client/graph_connection_test.rb
|
@@ -220,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
219
|
version: '0'
|
221
220
|
requirements: []
|
222
221
|
rubyforge_project:
|
223
|
-
rubygems_version: 2.6.
|
222
|
+
rubygems_version: 2.6.14
|
224
223
|
signing_key:
|
225
224
|
specification_version: 4
|
226
225
|
summary: ''
|
data/shipit.yml
DELETED