graphlient 0.3.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,6 +80,29 @@ describe Graphlient::Client do
80
80
  GRAPHQL
81
81
  end
82
82
 
83
+ let(:execution_error_query) do
84
+ <<-GRAPHQL
85
+ query($id: Int) {
86
+ executionErrorInvoice(id: $id) {
87
+ id
88
+ feeInCents
89
+ }
90
+ }
91
+ GRAPHQL
92
+ end
93
+
94
+ let(:partial_success_query) do
95
+ <<-GRAPHQL
96
+ query {
97
+ someInvoices {
98
+ id
99
+ feeInCents
100
+ createdAt
101
+ }
102
+ }
103
+ GRAPHQL
104
+ end
105
+
83
106
  it '#execute' do
84
107
  response = client.execute(query, id: 42)
85
108
  invoice = response.data.invoice
@@ -91,16 +114,15 @@ describe Graphlient::Client do
91
114
  expect do
92
115
  client.execute(query, id: '42')
93
116
  end.to raise_error Graphlient::Errors::GraphQLError do |e|
94
- expect(e.to_s).to eq 'Variable id of type Int was provided invalid value'
117
+ expect(e.to_s).to eq 'Variable $id of type Int was provided invalid value'
95
118
  end
96
119
  end
97
120
 
98
121
  it 'fails on an execution error' do
99
122
  expect do
100
- allow(OpenStruct).to receive(:new).and_raise StandardError, 'Unexpected error.'
101
- client.execute(query, id: 42)
123
+ client.execute(execution_error_query, id: 42)
102
124
  end.to raise_error Graphlient::Errors::ExecutionError do |e|
103
- expect(e.to_s).to eq 'invoice: Unexpected error.'
125
+ expect(e.to_s).to eq 'executionErrorInvoice: Execution Error'
104
126
  end
105
127
  end
106
128
 
@@ -119,6 +141,14 @@ describe Graphlient::Client do
119
141
  expect(e.response).to be_a GraphQL::Client::Response
120
142
  end
121
143
  end
144
+
145
+ it 'fails with a partial error response' do
146
+ expect do
147
+ client.execute(partial_success_query)
148
+ end.to raise_error Graphlient::Errors::ExecutionError do |e|
149
+ expect(e.response).to be_a GraphQL::Client::Response
150
+ end
151
+ end
122
152
  end
123
153
 
124
154
  context 'non-parameterized query' do
@@ -223,7 +253,7 @@ describe Graphlient::Client do
223
253
  end
224
254
  end
225
255
  end.to raise_error Graphlient::Errors::GraphQLError,
226
- 'Variable input of type CreateInvoiceInput! was provided invalid value'
256
+ 'Variable $input of type CreateInvoiceInput! was provided invalid value'
227
257
  end
228
258
 
229
259
  it 'returns a response from a query' do
@@ -272,7 +302,7 @@ describe Graphlient::Client do
272
302
  end
273
303
  end
274
304
  end.to raise_error Graphlient::Errors::GraphQLError,
275
- 'Variable input of type CreateInvoiceInput! was provided invalid value for feeInCents (Expected value to not be null)'
305
+ 'Variable $input of type CreateInvoiceInput! was provided invalid value for feeInCents (Expected value to not be null)'
276
306
  end
277
307
  end
278
308
  end
@@ -19,7 +19,7 @@ describe Graphlient::Client do
19
19
  it 'fails with an exception' do
20
20
  expect do
21
21
  client.schema
22
- end.to raise_error Graphlient::Errors::ServerError do |e|
22
+ end.to raise_error Graphlient::Errors::FaradayServerError do |e|
23
23
  expect(e.to_s).to eq 'the server responded with status 500'
24
24
  expect(e.status_code).to eq 500
25
25
  expect(e.response['errors'].size).to eq 1
@@ -10,7 +10,7 @@ describe Graphlient::Client do
10
10
  ) do |client|
11
11
  client.http do |h|
12
12
  h.connection do |c|
13
- c.use Faraday::Adapter::Rack, Sinatra::Application
13
+ c.adapter Faraday::Adapter::Rack, Sinatra::Application
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'App' do
4
+ let(:url) { 'http://graph.biz/graphql' }
5
+ let(:client) { Graphlient::Client.new(url, schema_path: 'spec/support/fixtures/invoice_api.json') }
6
+ let(:query) do
7
+ <<~GRAPHQL
8
+ query{
9
+ invoice(id: 42) {
10
+ id
11
+ feeInCents
12
+ }
13
+ }
14
+ GRAPHQL
15
+ end
16
+ let(:json_response) do
17
+ {
18
+ 'data' => {
19
+ 'invoice' => {
20
+ 'id' => '42',
21
+ 'feeInCents' => 2000
22
+ }
23
+ }
24
+ }.to_json
25
+ end
26
+
27
+ before do
28
+ stub_request(:post, url).to_return(
29
+ status: 200,
30
+ body: json_response
31
+ )
32
+ end
33
+
34
+ it 'returns invoice fees' do
35
+ response = client.query(query)
36
+ expect(response.data).to be_truthy
37
+ expect(response.data.invoice.id).to eq('42')
38
+ expect(response.data.invoice.fee_in_cents).to eq(2000)
39
+ end
40
+ end
@@ -18,7 +18,7 @@ RSpec.shared_context 'Dummy Client', shared_context: :metadata do
18
18
  Graphlient::Client.new(endpoint, headers: headers) do |client|
19
19
  client.http do |h|
20
20
  h.connection do |c|
21
- c.use Faraday::Adapter::Rack, app
21
+ c.adapter Faraday::Adapter::Rack, app
22
22
  end
23
23
  end
24
24
  end