graphlient 0.3.7 → 0.6.0
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/.github/workflows/ci.yml +29 -0
- data/.github/workflows/danger.yml +20 -0
- data/.github/workflows/rubocop.yml +19 -0
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +36 -18
- data/Gemfile +1 -1
- data/README.md +57 -4
- data/UPGRADING.md +11 -0
- data/graphlient.gemspec +1 -1
- data/lib/graphlient/adapters/http/adapter.rb +18 -0
- data/lib/graphlient/adapters/http/faraday_adapter.rb +8 -1
- data/lib/graphlient/adapters/http/http_adapter.rb +2 -0
- data/lib/graphlient/client.rb +5 -3
- data/lib/graphlient/errors/http_options_error.rb +6 -0
- data/lib/graphlient/errors/timeout_error.rb +6 -0
- data/lib/graphlient/errors.rb +2 -0
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/adapters/http/faraday_adapter_spec.rb +36 -5
- data/spec/graphlient/adapters/http/http_adapter_spec.rb +21 -2
- data/spec/graphlient/client_query_spec.rb +36 -6
- data/spec/graphlient/client_schema_spec.rb +1 -1
- data/spec/graphlient/static_client_query_spec.rb +1 -1
- data/spec/graphlient/webmock_client_query_spec.rb +40 -0
- data/spec/support/context/dummy_client.rb +1 -1
- data/spec/support/fixtures/invoice_api.json +1289 -0
- data/spec/support/mutations/create_invoice.rb +1 -0
- data/spec/support/queries/query.rb +23 -0
- data/spec/support/types/invoice_type.rb +6 -0
- metadata +16 -11
- data/.ruby-version +0 -1
- data/.travis.yml +0 -24
@@ -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
|
-
|
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 '
|
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::
|
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
|
@@ -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.
|
21
|
+
c.adapter Faraday::Adapter::Rack, app
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|