graphlient 0.7.0 → 0.9.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/ISSUE_TEMPLATE/bug_report.md +38 -38
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
- data/.github/workflows/ci.yml +33 -29
- data/.github/workflows/danger-comment.yml +10 -0
- data/.github/workflows/danger.yml +13 -22
- data/.github/workflows/rubocop.yml +19 -19
- data/.gitignore +59 -52
- data/.rspec +1 -1
- data/.rubocop.yml +26 -28
- data/.rubocop_todo.yml +72 -48
- data/CHANGELOG.md +128 -107
- data/CONTRIBUTING.md +125 -125
- data/Dangerfile +24 -24
- data/Gemfile +35 -27
- data/LICENSE +21 -21
- data/README.md +800 -508
- data/RELEASING.md +63 -63
- data/Rakefile +15 -15
- data/UPGRADING.md +23 -23
- data/graphlient.gemspec +19 -19
- data/lib/graphlient/adapters/http/adapter.rb +41 -41
- data/lib/graphlient/adapters/http/faraday_adapter.rb +79 -45
- data/lib/graphlient/adapters/http/http_adapter.rb +40 -39
- data/lib/graphlient/adapters/http.rb +3 -3
- data/lib/graphlient/adapters.rb +1 -1
- data/lib/graphlient/client.rb +98 -73
- data/lib/graphlient/errors/client_error.rb +6 -6
- data/lib/graphlient/errors/connection_failed_error.rb +6 -6
- data/lib/graphlient/errors/error.rb +13 -12
- data/lib/graphlient/errors/execution_error.rb +29 -29
- data/lib/graphlient/errors/faraday_server_error.rb +12 -12
- data/lib/graphlient/errors/graphql_error.rb +53 -52
- data/lib/graphlient/errors/http_options_error.rb +6 -6
- data/lib/graphlient/errors/http_server_error.rb +13 -13
- data/lib/graphlient/errors/server_error.rb +7 -7
- data/lib/graphlient/errors/timeout_error.rb +6 -6
- data/lib/graphlient/errors.rb +10 -10
- data/lib/graphlient/extensions/query.rb +15 -15
- data/lib/graphlient/extensions.rb +1 -1
- data/lib/graphlient/query/directive.rb +47 -0
- data/lib/graphlient/query/serializer/arguments.rb +67 -0
- data/lib/graphlient/query/serializer/directives.rb +17 -0
- data/lib/graphlient/query/serializer/evaluator.rb +15 -0
- data/lib/graphlient/query/serializer/fragments.rb +28 -0
- data/lib/graphlient/query/serializer/scalars.rb +63 -0
- data/lib/graphlient/query/serializer.rb +153 -0
- data/lib/graphlient/query.rb +29 -128
- data/lib/graphlient/schema.rb +27 -26
- data/lib/graphlient/version.rb +3 -3
- data/lib/graphlient.rb +8 -8
- data/spec/graphlient/adapters/http/faraday_adapter_spec.rb +172 -112
- data/spec/graphlient/adapters/http/http_adapter_spec.rb +60 -60
- data/spec/graphlient/client_dsl_spec.rb +153 -0
- data/spec/graphlient/client_query_spec.rb +369 -346
- data/spec/graphlient/client_schema_spec.rb +75 -55
- data/spec/graphlient/extensions/query_spec.rb +16 -16
- data/spec/graphlient/github_query_spec.rb +32 -32
- data/spec/graphlient/query_dsl_spec.rb +231 -0
- data/spec/graphlient/query_spec.rb +105 -105
- data/spec/graphlient/schema_spec.rb +56 -56
- data/spec/graphlient/static_client_query_spec.rb +75 -68
- data/spec/graphlient/webmock_client_query_spec.rb +41 -41
- data/spec/spec_helper.rb +26 -14
- data/spec/support/context/dummy_client.rb +33 -26
- data/spec/support/context/github_client.rb +18 -18
- data/spec/support/dummy_app.rb +21 -19
- data/spec/support/dummy_schema.rb +17 -17
- data/spec/support/fixtures/github/schema.yml +14282 -14282
- data/spec/support/fixtures/github/user.yml +76 -76
- data/spec/support/fixtures/github/viewer.yml +76 -76
- data/spec/support/fixtures/invoice_api.json +1288 -1288
- data/spec/support/mutations/create_invoice.rb +18 -18
- data/spec/support/queries/query.rb +48 -47
- data/spec/support/schema/github.json +44479 -44479
- data/spec/support/types/invoice_type.rb +13 -13
- data/spec/support/types/mutation_type.rb +5 -5
- data/spec/support/vcr.rb +9 -9
- metadata +13 -8
- data/Gemfile.danger +0 -5
|
@@ -1,346 +1,369 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Graphlient::Client do
|
|
4
|
-
include_context 'Dummy Client'
|
|
5
|
-
|
|
6
|
-
describe 'parse and execute' do
|
|
7
|
-
context 'non-parameterized query' do
|
|
8
|
-
let(:query) do
|
|
9
|
-
client.parse do
|
|
10
|
-
query do
|
|
11
|
-
invoice(id: 10) do
|
|
12
|
-
id
|
|
13
|
-
feeInCents
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it '#parse' do
|
|
20
|
-
expect(query).to be_a GraphQL::Client::OperationDefinition
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it '#execute' do
|
|
24
|
-
response = client.execute(query)
|
|
25
|
-
invoice = response.data.invoice
|
|
26
|
-
expect(invoice.id).to eq '10'
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'with fragment' do
|
|
30
|
-
let(:invoice_fragment) do
|
|
31
|
-
client.parse <<~'GRAPHQL'
|
|
32
|
-
fragment on Invoice {
|
|
33
|
-
id
|
|
34
|
-
feeInCents
|
|
35
|
-
}
|
|
36
|
-
GRAPHQL
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
let(:invoice_fragment_const) do
|
|
40
|
-
stub_const('Graphlient::InvoiceFragment', invoice_fragment)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
let(:query) do
|
|
44
|
-
invoice_fragment_const
|
|
45
|
-
client.parse do
|
|
46
|
-
query do
|
|
47
|
-
invoice(id: 10) do
|
|
48
|
-
___Graphlient__InvoiceFragment
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it '#parse' do
|
|
55
|
-
expect(query).to be_a GraphQL::Client::OperationDefinition
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it '#execute' do
|
|
59
|
-
response = client.execute(query)
|
|
60
|
-
invoice = response.data.invoice
|
|
61
|
-
fragment = invoice_fragment.new(invoice)
|
|
62
|
-
expect(fragment.id).to eq '10'
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context 'parameterized query' do
|
|
68
|
-
let(:query) do
|
|
69
|
-
client.parse do
|
|
70
|
-
query(some_id: :int) do
|
|
71
|
-
invoice(id: :some_id) do
|
|
72
|
-
id
|
|
73
|
-
feeInCents
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it '#parse' do
|
|
80
|
-
expect(query).to be_a GraphQL::Client::OperationDefinition
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it '#execute' do
|
|
84
|
-
response = client.execute(query, some_id: 42)
|
|
85
|
-
invoice = response.data.invoice
|
|
86
|
-
expect(invoice.id).to eq '42'
|
|
87
|
-
expect(invoice.fee_in_cents).to eq 20_000
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it '#execute without variables' do
|
|
91
|
-
response = client.execute(query)
|
|
92
|
-
invoice = response.data.invoice
|
|
93
|
-
expect(invoice).to be_nil
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
GRAPHQL
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it '
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Graphlient::Client do
|
|
4
|
+
include_context 'Dummy Client'
|
|
5
|
+
|
|
6
|
+
describe 'parse and execute' do
|
|
7
|
+
context 'non-parameterized query' do
|
|
8
|
+
let(:query) do
|
|
9
|
+
client.parse do
|
|
10
|
+
query do
|
|
11
|
+
invoice(id: 10) do
|
|
12
|
+
id
|
|
13
|
+
feeInCents
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it '#parse' do
|
|
20
|
+
expect(query).to be_a GraphQL::Client::OperationDefinition
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it '#execute' do
|
|
24
|
+
response = client.execute(query)
|
|
25
|
+
invoice = response.data.invoice
|
|
26
|
+
expect(invoice.id).to eq '10'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'with fragment' do
|
|
30
|
+
let(:invoice_fragment) do
|
|
31
|
+
client.parse <<~'GRAPHQL'
|
|
32
|
+
fragment on Invoice {
|
|
33
|
+
id
|
|
34
|
+
feeInCents
|
|
35
|
+
}
|
|
36
|
+
GRAPHQL
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
let(:invoice_fragment_const) do
|
|
40
|
+
stub_const('Graphlient::InvoiceFragment', invoice_fragment)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
let(:query) do
|
|
44
|
+
invoice_fragment_const
|
|
45
|
+
client.parse do
|
|
46
|
+
query do
|
|
47
|
+
invoice(id: 10) do
|
|
48
|
+
___Graphlient__InvoiceFragment
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it '#parse' do
|
|
55
|
+
expect(query).to be_a GraphQL::Client::OperationDefinition
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it '#execute' do
|
|
59
|
+
response = client.execute(query)
|
|
60
|
+
invoice = response.data.invoice
|
|
61
|
+
fragment = invoice_fragment.new(invoice)
|
|
62
|
+
expect(fragment.id).to eq '10'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'parameterized query' do
|
|
68
|
+
let(:query) do
|
|
69
|
+
client.parse do
|
|
70
|
+
query(some_id: :int) do
|
|
71
|
+
invoice(id: :some_id) do
|
|
72
|
+
id
|
|
73
|
+
feeInCents
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it '#parse' do
|
|
80
|
+
expect(query).to be_a GraphQL::Client::OperationDefinition
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it '#execute' do
|
|
84
|
+
response = client.execute(query, some_id: 42)
|
|
85
|
+
invoice = response.data.invoice
|
|
86
|
+
expect(invoice.id).to eq '42'
|
|
87
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it '#execute without variables' do
|
|
91
|
+
response = client.execute(query)
|
|
92
|
+
invoice = response.data.invoice
|
|
93
|
+
expect(invoice).to be_nil
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
context 'with directive' do
|
|
97
|
+
let(:query) do
|
|
98
|
+
client.parse do
|
|
99
|
+
query(
|
|
100
|
+
some_id: :int,
|
|
101
|
+
skip_fee: :boolean!
|
|
102
|
+
) do
|
|
103
|
+
invoice(id: :some_id) do
|
|
104
|
+
id
|
|
105
|
+
feeInCents _skip(if: :skip_fee)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it '#execute' do
|
|
112
|
+
response = client.execute(query, some_id: 42, skip_fee: true)
|
|
113
|
+
invoice = response.data.invoice
|
|
114
|
+
expect(invoice.id).to eq '42'
|
|
115
|
+
expect(invoice.fee_in_cents).to eq nil
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
context 'parameterized GRAPHQL query' do
|
|
121
|
+
let(:query) do
|
|
122
|
+
<<-GRAPHQL
|
|
123
|
+
query($id: Int) {
|
|
124
|
+
invoice(id: $id) {
|
|
125
|
+
id
|
|
126
|
+
feeInCents
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
GRAPHQL
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
let(:not_null_query) do
|
|
133
|
+
<<-GRAPHQL
|
|
134
|
+
query($id: Int) {
|
|
135
|
+
notNullInvoice(id: $id) {
|
|
136
|
+
id
|
|
137
|
+
feeInCents
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
GRAPHQL
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
let(:execution_error_query) do
|
|
144
|
+
<<-GRAPHQL
|
|
145
|
+
query($id: Int) {
|
|
146
|
+
executionErrorInvoice(id: $id) {
|
|
147
|
+
id
|
|
148
|
+
feeInCents
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
GRAPHQL
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
let(:partial_success_query) do
|
|
155
|
+
<<-GRAPHQL
|
|
156
|
+
query {
|
|
157
|
+
someInvoices {
|
|
158
|
+
id
|
|
159
|
+
feeInCents
|
|
160
|
+
createdAt
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
GRAPHQL
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it '#execute' do
|
|
167
|
+
response = client.execute(query, id: 42)
|
|
168
|
+
invoice = response.data.invoice
|
|
169
|
+
expect(invoice.id).to eq '42'
|
|
170
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'fails when wrong input type' do
|
|
174
|
+
expect do
|
|
175
|
+
client.execute(query, id: '42')
|
|
176
|
+
end.to raise_error Graphlient::Errors::GraphQLError do |e|
|
|
177
|
+
expect(e.to_s).to eq 'Variable $id of type Int was provided invalid value'
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'fails on an execution error' do
|
|
182
|
+
expect do
|
|
183
|
+
client.execute(execution_error_query, id: 42)
|
|
184
|
+
end.to raise_error Graphlient::Errors::ExecutionError do |e|
|
|
185
|
+
expect(e.to_s).to eq 'executionErrorInvoice: Execution Error'
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it 'fails with proper error message' do
|
|
190
|
+
expect do
|
|
191
|
+
client.execute(not_null_query, id: 42)
|
|
192
|
+
end.to raise_error Graphlient::Errors::GraphQLError do |e|
|
|
193
|
+
expect(e.to_s).to eq 'Cannot return null for non-nullable field Query.notNullInvoice'
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it 'fails with access to the response' do
|
|
198
|
+
expect do
|
|
199
|
+
client.execute(not_null_query, id: 42)
|
|
200
|
+
end.to raise_error Graphlient::Errors::GraphQLError do |e|
|
|
201
|
+
expect(e.response).to be_a GraphQL::Client::Response
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it 'fails with a partial error response' do
|
|
206
|
+
expect do
|
|
207
|
+
client.execute(partial_success_query)
|
|
208
|
+
end.to raise_error Graphlient::Errors::ExecutionError do |e|
|
|
209
|
+
expect(e.response).to be_a GraphQL::Client::Response
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
context 'non-parameterized query' do
|
|
215
|
+
let(:query) do
|
|
216
|
+
<<-GRAPHQL
|
|
217
|
+
query($someId: Int) {
|
|
218
|
+
invoices(id: $someId) {
|
|
219
|
+
id
|
|
220
|
+
feeInCents
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
GRAPHQL
|
|
224
|
+
end
|
|
225
|
+
it 'fails client-side on invalid schema' do
|
|
226
|
+
expect do
|
|
227
|
+
client.execute(query, some_id: 'NASDASASD')
|
|
228
|
+
end.to raise_error Graphlient::Errors::ClientError do |e|
|
|
229
|
+
expect(e.to_s).to eq "Field 'invoices' doesn't exist on type 'Query'"
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
describe '#query' do
|
|
236
|
+
context 'non-parameterized query' do
|
|
237
|
+
it 'fails client-side on invalid schema' do
|
|
238
|
+
expect do
|
|
239
|
+
client.query do
|
|
240
|
+
query do
|
|
241
|
+
invoices(id: 10) do
|
|
242
|
+
id
|
|
243
|
+
feeInCents
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end.to raise_error Graphlient::Errors::ClientError do |e|
|
|
248
|
+
expect(e.to_s).to eq "Field 'invoices' doesn't exist on type 'Query'"
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it 'returns a response from a query' do
|
|
253
|
+
response = client.query do
|
|
254
|
+
query do
|
|
255
|
+
invoice(id: 10) do
|
|
256
|
+
id
|
|
257
|
+
feeInCents
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
invoice = response.data.invoice
|
|
263
|
+
expect(invoice.id).to eq '10'
|
|
264
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it 'returns a response from a GRAPHQL query' do
|
|
268
|
+
response = client.query <<-GRAPHQL
|
|
269
|
+
query {
|
|
270
|
+
invoice(id: 10) {
|
|
271
|
+
id
|
|
272
|
+
feeInCents
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
GRAPHQL
|
|
276
|
+
|
|
277
|
+
invoice = response.data.invoice
|
|
278
|
+
expect(invoice.id).to eq '10'
|
|
279
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
it 'returns a response from a mutation' do
|
|
283
|
+
response = client.query do
|
|
284
|
+
mutation do
|
|
285
|
+
createInvoice(input: { feeInCents: 12_345 }) do
|
|
286
|
+
invoice do
|
|
287
|
+
id
|
|
288
|
+
feeInCents
|
|
289
|
+
end
|
|
290
|
+
errors
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
invoice = response.data.create_invoice.invoice
|
|
296
|
+
expect(invoice.id).to eq '1231'
|
|
297
|
+
expect(invoice.fee_in_cents).to eq 12_345
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
context 'parameterized query' do
|
|
302
|
+
it 'fails when missing input' do
|
|
303
|
+
expect do
|
|
304
|
+
client.query do
|
|
305
|
+
mutation(input: :CreateInvoiceInput!) do
|
|
306
|
+
createInvoice(input: :input) do
|
|
307
|
+
invoice do
|
|
308
|
+
id
|
|
309
|
+
feeInCents
|
|
310
|
+
end
|
|
311
|
+
errors
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
end.to raise_error Graphlient::Errors::GraphQLError,
|
|
316
|
+
'Variable $input of type CreateInvoiceInput! was provided invalid value'
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
it 'returns a response from a query' do
|
|
320
|
+
response = client.query(id: 42) do
|
|
321
|
+
query(id: :int) do
|
|
322
|
+
invoice(id: :id) do
|
|
323
|
+
id
|
|
324
|
+
feeInCents
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
invoice = response.data.invoice
|
|
330
|
+
expect(invoice.id).to eq '42'
|
|
331
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
it 'executes the mutation' do
|
|
335
|
+
response = client.query(input: { feeInCents: 12_345 }) do
|
|
336
|
+
mutation(input: :CreateInvoiceInput!) do
|
|
337
|
+
createInvoice(input: :input) do
|
|
338
|
+
invoice do
|
|
339
|
+
id
|
|
340
|
+
feeInCents
|
|
341
|
+
end
|
|
342
|
+
errors
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
invoice = response.data.create_invoice.invoice
|
|
347
|
+
expect(invoice.id).to eq '1231'
|
|
348
|
+
expect(invoice.fee_in_cents).to eq 12_345
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
it 'fails when mutation missing a field' do
|
|
352
|
+
expect do
|
|
353
|
+
client.query(input: {}) do
|
|
354
|
+
mutation(input: :CreateInvoiceInput!) do
|
|
355
|
+
createInvoice(input: :input) do
|
|
356
|
+
invoice do
|
|
357
|
+
id
|
|
358
|
+
feeInCents
|
|
359
|
+
end
|
|
360
|
+
errors
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
end.to raise_error Graphlient::Errors::GraphQLError,
|
|
365
|
+
'Variable $input of type CreateInvoiceInput! was provided invalid value for feeInCents (Expected value to not be null)'
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
end
|