graphql_client 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e4afa9a8d44f51f59d674a378869ed6ba86c250
4
- data.tar.gz: 3538662487a766eca54ffe3fb5f73b0543785852
3
+ metadata.gz: ef03a205ab7279feb064cf18c8155e51bcec815d
4
+ data.tar.gz: 37dd8c3bf4cff061652a9695aece60c98cc8d30b
5
5
  SHA512:
6
- metadata.gz: 13d946560d0627dfbb0bea51badf3906f9ef39d935d8ccd3f3e8e01bfc3f64a1a59cd891bbfee52eed6417d7d7bdcdb461b4e087e87ec92291392d5f74dfe976
7
- data.tar.gz: 18d6a2125bc01d98ed2ea172b64da931ab83e27547e2aa8436edba7b3a77f87a42ecfda43b39d32cf63b8aa33341dd16c09394e16b0d48e5ecada3c18c0754e7
6
+ metadata.gz: 4b39ab7a0b9a8f66fe8f784404e58c65421e73366027acb8672a75af1a13ccf579ad1d580aeb574d2472d0889ca970d375a85a2a0a7a79cac73387bf55d3cf86
7
+ data.tar.gz: '093ddc0a6dd2e375ff7beb410dc46dbf6b47d48f24329558276d468ebd179f31dc4da3c93da381b22108708bd9ece30620c6a59161cda15a1818324c8f79538a'
@@ -1,3 +1,7 @@
1
+ ## 0.4.0
2
+
3
+ - Added a `raw_query_with_extensions` method to the client which returns both `data` and `extensions` keys as response objects.
4
+
1
5
  ## 0.3.3
2
6
 
3
7
  This is the initial public release of the GraphQL Ruby client.
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
+ ```
@@ -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 << 'graphql-client'
15
+ s.executables = 'graphql-client'
16
16
 
17
17
  s.add_runtime_dependency 'graphql_schema', '~> 0.1.5'
18
18
 
@@ -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
@@ -14,7 +14,7 @@ module GraphQL
14
14
  @body = response
15
15
  @data = data
16
16
  @errors = errors.to_a
17
- @extensions = extensions.to_a
17
+ @extensions = extensions
18
18
  end
19
19
  end
20
20
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Client
5
- VERSION = '0.3.3'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  end
@@ -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 [{ 'foo' => 'bar' }], response.extensions
42
+ assert_equal({ 'foo' => 'bar' }, response.extensions)
45
43
  end
46
44
 
47
- def test_initialize_sets_extensions_default
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
- assert_equal [], response.extensions
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.3.3
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: 2017-12-07 00:00:00.000000000 Z
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.8
222
+ rubygems_version: 2.6.14
224
223
  signing_key:
225
224
  specification_version: 4
226
225
  summary: ''
data/shipit.yml DELETED
@@ -1,4 +0,0 @@
1
- deploy:
2
- override:
3
- - bundle exec rake build
4
- - bundle exec package_cloud push shopify/gems pkg/*.gem