graphlient 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +25 -8
- data/.travis.yml +3 -1
- data/CHANGELOG.md +7 -2
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/graphlient/adapters/http/http_adapter.rb +1 -1
- data/lib/graphlient/client.rb +1 -1
- data/lib/graphlient/errors/graphql_error.rb +14 -5
- data/lib/graphlient/query.rb +1 -1
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/client_query_spec.rb +94 -64
- data/spec/graphlient/static_client_query_spec.rb +7 -7
- data/spec/support/dummy_schema.rb +4 -4
- data/spec/support/mutations/create_invoice.rb +17 -0
- data/spec/support/queries/query.rb +21 -13
- data/spec/support/types/invoice_type.rb +5 -4
- data/spec/support/types/mutation_type.rb +5 -0
- metadata +4 -4
- data/spec/support/mutations/create_invoice_mutation.rb +0 -16
- data/spec/support/mutations/mutation.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34caaff4616027770512deba3bd043d83379d84f
|
4
|
+
data.tar.gz: 95ee485aee51537d6e90e67aa4616ce1db4bcef9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce7dd3f6274fee8b92c674f833bde196cb5195c34e06e07911b5753aa20d41c9a16d0e041fac8b9f4ab57f3eb6b8deffe6ae6c87c5e59682c0b5e182f46412d8
|
7
|
+
data.tar.gz: 3334aeb5aa4c80d8a715b9a74fd5b7f657e5bd8403f8cc0ac927059416b913818758c0c34ba18f45656756c210a1da2520b4f301c8f7b336ba691faae971469e
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2018-05-17 08:20:20 -0500 using RuboCop version 0.56.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -13,16 +13,23 @@ Lint/UnusedMethodArgument:
|
|
13
13
|
Exclude:
|
14
14
|
- 'lib/graphlient/adapters/http/http_adapter.rb'
|
15
15
|
|
16
|
-
# Offense count:
|
16
|
+
# Offense count: 2
|
17
17
|
Metrics/CyclomaticComplexity:
|
18
|
-
Max:
|
18
|
+
Max: 8
|
19
19
|
|
20
20
|
# Offense count: 1
|
21
21
|
Metrics/PerceivedComplexity:
|
22
|
-
Max:
|
22
|
+
Max: 8
|
23
|
+
|
24
|
+
# Offense count: 1
|
25
|
+
# Cop supports --auto-correct.
|
26
|
+
Performance/InefficientHashSearch:
|
27
|
+
Exclude:
|
28
|
+
- 'lib/graphlient/query.rb'
|
23
29
|
|
24
30
|
# Offense count: 1
|
25
|
-
#
|
31
|
+
# Cop supports --auto-correct.
|
32
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
26
33
|
# SupportedStyles: nested, compact
|
27
34
|
Style/ClassAndModuleChildren:
|
28
35
|
Exclude:
|
@@ -30,7 +37,7 @@ Style/ClassAndModuleChildren:
|
|
30
37
|
|
31
38
|
# Offense count: 2
|
32
39
|
# Cop supports --auto-correct.
|
33
|
-
# Configuration parameters: EnforcedStyle
|
40
|
+
# Configuration parameters: EnforcedStyle.
|
34
41
|
# SupportedStyles: line_count_dependent, lambda, literal
|
35
42
|
Style/Lambda:
|
36
43
|
Exclude:
|
@@ -38,7 +45,7 @@ Style/Lambda:
|
|
38
45
|
- 'spec/support/queries/query.rb'
|
39
46
|
|
40
47
|
# Offense count: 2
|
41
|
-
Style/
|
48
|
+
Style/MethodMissingSuper:
|
42
49
|
Exclude:
|
43
50
|
- 'lib/graphlient/extensions/query.rb'
|
44
51
|
- 'lib/graphlient/query.rb'
|
@@ -49,7 +56,17 @@ Style/MultilineBlockChain:
|
|
49
56
|
- 'spec/graphlient/client_query_spec.rb'
|
50
57
|
- 'spec/graphlient/client_schema_spec.rb'
|
51
58
|
|
59
|
+
# Offense count: 2
|
60
|
+
# Cop supports --auto-correct.
|
61
|
+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist.
|
62
|
+
# Whitelist: present?, blank?, presence, try, try!
|
52
63
|
Style/SafeNavigation:
|
53
64
|
Exclude:
|
54
|
-
- 'lib/graphlient/client.rb'
|
55
65
|
- 'lib/graphlient/adapters/http/http_adapter.rb'
|
66
|
+
- 'lib/graphlient/client.rb'
|
67
|
+
|
68
|
+
# Offense count: 37
|
69
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
70
|
+
# URISchemes: http, https
|
71
|
+
Metrics/LineLength:
|
72
|
+
Max: 181
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
###
|
1
|
+
### (Next)
|
2
2
|
|
3
|
-
* [#43](https://github.com/ashkan18/graphlient/pull/38): Allow to load and dump schema to json - [@povilasjurcys](https://github.com/povilasjurcys).
|
4
3
|
* Your contribution here.
|
4
|
+
* [#46](https://github.com/ashkan18/graphlient/pull/46): Fix issue with gathering error details when trying `to_s` on `GraphQLError` - [@ashkan18](https://github.com/ashkan18).
|
5
|
+
* [#45](https://github.com/ashkan18/graphlient/pull/45): Drop Support for Ruby 2.2 and Lock RuboCop - [@jonallured](https://github.com/jonallured).
|
6
|
+
|
7
|
+
### 0.3.1 (04/17/2018)
|
8
|
+
|
9
|
+
* [#43](https://github.com/ashkan18/graphlient/pull/43): Allow to load and dump schema to json - [@povilasjurcys](https://github.com/povilasjurcys).
|
5
10
|
|
6
11
|
### 0.3.0 (02/22/2018)
|
7
12
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ module Graphlient
|
|
9
9
|
|
10
10
|
request['Accept'] = 'application/json'
|
11
11
|
request['Content-Type'] = 'application/json'
|
12
|
-
headers
|
12
|
+
headers&.each { |name, value| request[name] = value }
|
13
13
|
|
14
14
|
body = {}
|
15
15
|
body['query'] = document.to_query_string
|
data/lib/graphlient/client.rb
CHANGED
@@ -26,7 +26,7 @@ module Graphlient
|
|
26
26
|
raise Graphlient::Errors::GraphQLError, rc if rc.errors.any?
|
27
27
|
# see https://github.com/github/graphql-client/pull/132
|
28
28
|
# see https://github.com/exAspArk/graphql-errors/issues/2
|
29
|
-
raise Graphlient::Errors::ExecutionError, rc if rc.data
|
29
|
+
raise Graphlient::Errors::ExecutionError, rc if rc.data&.errors && rc.data.errors.any?
|
30
30
|
rc
|
31
31
|
rescue GraphQL::Client::Error => e
|
32
32
|
raise Graphlient::Errors::ClientError.new(e.message, e)
|
@@ -25,9 +25,19 @@ module Graphlient
|
|
25
25
|
details.map { |detail| create_detail(detail) }
|
26
26
|
end
|
27
27
|
|
28
|
+
##
|
29
|
+
# Generates human readable error explanation from a GraphQL error message
|
30
|
+
# It first tries `problem` attribute of the error response
|
31
|
+
# then checks for error root level `path` and tries to generate error from that
|
32
|
+
# and if none exist, it fallbacks to just return error message
|
28
33
|
def create_detail(detail)
|
29
|
-
|
30
|
-
|
34
|
+
if detail.key?('problems')
|
35
|
+
[detail['message'], create_problems(detail['problems']).compact.join("\n ")].join("\n ")
|
36
|
+
elsif detail.key?('path')
|
37
|
+
[detail['path'].compact.join(' '), detail['message']].join(': ')
|
38
|
+
else
|
39
|
+
detail['message']
|
40
|
+
end
|
31
41
|
end
|
32
42
|
|
33
43
|
def create_problems(problems)
|
@@ -35,9 +45,8 @@ module Graphlient
|
|
35
45
|
end
|
36
46
|
|
37
47
|
def create_problem(problem)
|
38
|
-
paths = problem['path'].join(', ')
|
39
|
-
|
40
|
-
[paths, explanation].join(': ')
|
48
|
+
paths = problem.key?('path') && !problem['path'].empty? ? "#{problem['path'].join(', ')}: " : ''
|
49
|
+
[paths, problem['explanation']].compact.join
|
41
50
|
end
|
42
51
|
end
|
43
52
|
end
|
data/lib/graphlient/query.rb
CHANGED
@@ -100,7 +100,7 @@ module Graphlient
|
|
100
100
|
when Hash
|
101
101
|
"{ #{value.map { |k, v| "#{k}: #{argument_value_string(v)}" }.join(', ')} }"
|
102
102
|
when Symbol
|
103
|
-
@variables.
|
103
|
+
@variables.key?(value) ? "$#{value}" : value.to_s.camelize(:lower)
|
104
104
|
else
|
105
105
|
value
|
106
106
|
end
|
data/lib/graphlient/version.rb
CHANGED
@@ -8,9 +8,9 @@ describe Graphlient::Client do
|
|
8
8
|
let(:query) do
|
9
9
|
client.parse do
|
10
10
|
query do
|
11
|
-
|
11
|
+
invoice(id: 10) do
|
12
12
|
id
|
13
|
-
|
13
|
+
feeInCents
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -22,18 +22,18 @@ describe Graphlient::Client do
|
|
22
22
|
|
23
23
|
it '#execute' do
|
24
24
|
response = client.execute(query)
|
25
|
-
|
26
|
-
expect(
|
25
|
+
invoice = response.data.invoice
|
26
|
+
expect(invoice.id).to eq '10'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'parameterized query' do
|
31
31
|
let(:query) do
|
32
32
|
client.parse do
|
33
|
-
query(
|
34
|
-
|
33
|
+
query(some_id: :int) do
|
34
|
+
invoice(id: :some_id) do
|
35
35
|
id
|
36
|
-
|
36
|
+
feeInCents
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -44,52 +44,71 @@ describe Graphlient::Client do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it '#execute' do
|
47
|
-
response = client.execute(query,
|
48
|
-
|
49
|
-
expect(
|
50
|
-
expect(
|
47
|
+
response = client.execute(query, some_id: 42)
|
48
|
+
invoice = response.data.invoice
|
49
|
+
expect(invoice.id).to eq '42'
|
50
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
51
51
|
end
|
52
52
|
|
53
53
|
it '#execute without variables' do
|
54
54
|
response = client.execute(query)
|
55
|
-
|
56
|
-
expect(
|
55
|
+
invoice = response.data.invoice
|
56
|
+
expect(invoice).to be_nil
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'parameterized GRAPHQL query' do
|
61
61
|
let(:query) do
|
62
62
|
<<-GRAPHQL
|
63
|
-
query($
|
64
|
-
|
63
|
+
query($id: Int) {
|
64
|
+
invoice(id: $id) {
|
65
65
|
id
|
66
|
-
|
66
|
+
feeInCents
|
67
|
+
}
|
68
|
+
}
|
69
|
+
GRAPHQL
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:not_null_query) do
|
73
|
+
<<-GRAPHQL
|
74
|
+
query($id: Int) {
|
75
|
+
notNullInvoice(id: $id) {
|
76
|
+
id
|
77
|
+
feeInCents
|
67
78
|
}
|
68
79
|
}
|
69
80
|
GRAPHQL
|
70
81
|
end
|
71
82
|
|
72
83
|
it '#execute' do
|
73
|
-
response = client.execute(query,
|
74
|
-
|
75
|
-
expect(
|
76
|
-
expect(
|
84
|
+
response = client.execute(query, id: 42)
|
85
|
+
invoice = response.data.invoice
|
86
|
+
expect(invoice.id).to eq '42'
|
87
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
77
88
|
end
|
78
89
|
|
79
90
|
it 'fails when wrong input type' do
|
80
91
|
expect do
|
81
|
-
client.execute(query,
|
92
|
+
client.execute(query, id: '42')
|
82
93
|
end.to raise_error Graphlient::Errors::GraphQLError do |e|
|
83
|
-
expect(e.to_s).to eq "Variable
|
94
|
+
expect(e.to_s).to eq "Variable id of type Int was provided invalid value\n Could not coerce value \"42\" to Int"
|
84
95
|
end
|
85
96
|
end
|
86
97
|
|
87
98
|
it 'fails on an execution error' do
|
88
99
|
expect do
|
89
100
|
allow(OpenStruct).to receive(:new).and_raise StandardError, 'Unexpected error.'
|
90
|
-
client.execute(query,
|
101
|
+
client.execute(query, id: 42)
|
91
102
|
end.to raise_error Graphlient::Errors::ExecutionError do |e|
|
92
|
-
expect(e.to_s).to eq '
|
103
|
+
expect(e.to_s).to eq 'invoice: Unexpected error.'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'fails with proper error message' do
|
108
|
+
expect do
|
109
|
+
client.execute(not_null_query, id: 42)
|
110
|
+
end.to raise_error Graphlient::Errors::GraphQLError do |e|
|
111
|
+
expect(e.to_s).to eq 'Cannot return null for non-nullable field Query.notNullInvoice'
|
93
112
|
end
|
94
113
|
end
|
95
114
|
end
|
@@ -101,59 +120,62 @@ describe Graphlient::Client do
|
|
101
120
|
expect do
|
102
121
|
client.query do
|
103
122
|
query do
|
104
|
-
|
123
|
+
invoices(id: 10) do
|
105
124
|
id
|
106
|
-
|
125
|
+
feeInCents
|
107
126
|
end
|
108
127
|
end
|
109
128
|
end
|
110
129
|
end.to raise_error Graphlient::Errors::ClientError do |e|
|
111
|
-
expect(e.to_s).to eq "Field '
|
130
|
+
expect(e.to_s).to eq "Field 'invoices' doesn't exist on type 'Query'"
|
112
131
|
end
|
113
132
|
end
|
114
133
|
|
115
134
|
it 'returns a response from a query' do
|
116
135
|
response = client.query do
|
117
136
|
query do
|
118
|
-
|
137
|
+
invoice(id: 10) do
|
119
138
|
id
|
120
|
-
|
139
|
+
feeInCents
|
121
140
|
end
|
122
141
|
end
|
123
142
|
end
|
124
143
|
|
125
|
-
|
126
|
-
expect(
|
127
|
-
expect(
|
144
|
+
invoice = response.data.invoice
|
145
|
+
expect(invoice.id).to eq '10'
|
146
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
128
147
|
end
|
129
148
|
|
130
149
|
it 'returns a response from a GRAPHQL query' do
|
131
150
|
response = client.query <<-GRAPHQL
|
132
151
|
query {
|
133
|
-
|
152
|
+
invoice(id: 10) {
|
134
153
|
id
|
135
|
-
|
154
|
+
feeInCents
|
136
155
|
}
|
137
156
|
}
|
138
157
|
GRAPHQL
|
139
158
|
|
140
|
-
|
141
|
-
expect(
|
142
|
-
expect(
|
159
|
+
invoice = response.data.invoice
|
160
|
+
expect(invoice.id).to eq '10'
|
161
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
143
162
|
end
|
144
163
|
|
145
164
|
it 'returns a response from a mutation' do
|
146
165
|
response = client.query do
|
147
166
|
mutation do
|
148
|
-
createInvoice(input: {
|
149
|
-
|
150
|
-
|
167
|
+
createInvoice(input: { feeInCents: 12_345 }) do
|
168
|
+
invoice do
|
169
|
+
id
|
170
|
+
feeInCents
|
171
|
+
end
|
172
|
+
errors
|
151
173
|
end
|
152
174
|
end
|
153
175
|
end
|
154
176
|
|
155
|
-
invoice = response.data.create_invoice.
|
156
|
-
expect(invoice.id).to eq 1231
|
177
|
+
invoice = response.data.create_invoice.invoice
|
178
|
+
expect(invoice.id).to eq '1231'
|
157
179
|
expect(invoice.fee_in_cents).to eq 12_345
|
158
180
|
end
|
159
181
|
end
|
@@ -162,59 +184,67 @@ describe Graphlient::Client do
|
|
162
184
|
it 'fails when missing input' do
|
163
185
|
expect do
|
164
186
|
client.query do
|
165
|
-
mutation(input: :
|
187
|
+
mutation(input: :CreateInvoiceInput!) do
|
166
188
|
createInvoice(input: :input) do
|
167
|
-
|
168
|
-
|
189
|
+
invoice do
|
190
|
+
id
|
191
|
+
feeInCents
|
192
|
+
end
|
193
|
+
errors
|
169
194
|
end
|
170
195
|
end
|
171
196
|
end
|
172
197
|
end.to raise_error Graphlient::Errors::GraphQLError,
|
173
|
-
"Variable input of type
|
198
|
+
"Variable input of type CreateInvoiceInput! was provided invalid value\n Expected value to not be null"
|
174
199
|
end
|
175
200
|
|
176
201
|
it 'returns a response from a query' do
|
177
|
-
response = client.query(
|
178
|
-
query(
|
179
|
-
|
202
|
+
response = client.query(id: 42) do
|
203
|
+
query(id: :int) do
|
204
|
+
invoice(id: :id) do
|
180
205
|
id
|
181
|
-
|
206
|
+
feeInCents
|
182
207
|
end
|
183
208
|
end
|
184
209
|
end
|
185
210
|
|
186
|
-
|
187
|
-
expect(
|
188
|
-
expect(
|
211
|
+
invoice = response.data.invoice
|
212
|
+
expect(invoice.id).to eq '42'
|
213
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
189
214
|
end
|
190
215
|
|
191
216
|
it 'executes the mutation' do
|
192
|
-
response = client.query(input: {
|
193
|
-
mutation(input: :
|
217
|
+
response = client.query(input: { feeInCents: 12_345 }) do
|
218
|
+
mutation(input: :CreateInvoiceInput!) do
|
194
219
|
createInvoice(input: :input) do
|
195
|
-
|
196
|
-
|
220
|
+
invoice do
|
221
|
+
id
|
222
|
+
feeInCents
|
223
|
+
end
|
224
|
+
errors
|
197
225
|
end
|
198
226
|
end
|
199
227
|
end
|
200
|
-
|
201
|
-
invoice
|
202
|
-
expect(invoice.id).to eq 1231
|
228
|
+
invoice = response.data.create_invoice.invoice
|
229
|
+
expect(invoice.id).to eq '1231'
|
203
230
|
expect(invoice.fee_in_cents).to eq 12_345
|
204
231
|
end
|
205
232
|
|
206
233
|
it 'fails when mutation missing a field' do
|
207
234
|
expect do
|
208
235
|
client.query(input: {}) do
|
209
|
-
mutation(input: :
|
236
|
+
mutation(input: :CreateInvoiceInput!) do
|
210
237
|
createInvoice(input: :input) do
|
211
|
-
|
212
|
-
|
238
|
+
invoice do
|
239
|
+
id
|
240
|
+
feeInCents
|
241
|
+
end
|
242
|
+
errors
|
213
243
|
end
|
214
244
|
end
|
215
245
|
end
|
216
246
|
end.to raise_error Graphlient::Errors::GraphQLError,
|
217
|
-
"Variable input of type
|
247
|
+
"Variable input of type CreateInvoiceInput! was provided invalid value\n feeInCents: Expected value to not be null"
|
218
248
|
end
|
219
249
|
end
|
220
250
|
end
|
@@ -16,10 +16,10 @@ describe Graphlient::Client do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Query = Client.parse do
|
19
|
-
query(
|
20
|
-
|
19
|
+
query(some_id: :int) do
|
20
|
+
invoice(id: :some_id) do
|
21
21
|
id
|
22
|
-
|
22
|
+
feeInCents
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -30,10 +30,10 @@ describe Graphlient::Client do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it '#execute' do
|
33
|
-
response = Graphlient::Client::Spec::Client.execute(Graphlient::Client::Spec::Query,
|
34
|
-
|
35
|
-
expect(
|
36
|
-
expect(
|
33
|
+
response = Graphlient::Client::Spec::Client.execute(Graphlient::Client::Spec::Query, some_id: 42)
|
34
|
+
invoice = response.data.invoice
|
35
|
+
expect(invoice.id).to eq '42'
|
36
|
+
expect(invoice.fee_in_cents).to eq 20_000
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative 'types/invoice_type'
|
2
2
|
|
3
3
|
require_relative 'queries/query'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'types/mutation_type.rb'
|
5
5
|
|
6
6
|
require 'graphql/errors'
|
7
7
|
|
8
|
-
DummySchema
|
9
|
-
query
|
10
|
-
mutation
|
8
|
+
class DummySchema < GraphQL::Schema
|
9
|
+
query(Query)
|
10
|
+
mutation(MutationType)
|
11
11
|
end
|
12
12
|
|
13
13
|
GraphQL::Errors.configure(DummySchema) do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateInvoice < GraphQL::Schema::RelayClassicMutation
|
2
|
+
null true
|
3
|
+
|
4
|
+
argument :fee_in_cents, Integer, required: true
|
5
|
+
|
6
|
+
field :invoice, InvoiceType, null: true
|
7
|
+
field :errors, [String], null: true
|
8
|
+
|
9
|
+
def resolve(fee_in_cents:)
|
10
|
+
{
|
11
|
+
invoice: OpenStruct.new(
|
12
|
+
id: 1231,
|
13
|
+
fee_in_cents: fee_in_cents
|
14
|
+
)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
@@ -1,16 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative '../types/invoice_type'
|
2
|
+
class Query < GraphQL::Schema::Object
|
3
|
+
field :invoice, InvoiceType, null: true do
|
4
|
+
description 'Find invoice'
|
5
|
+
argument :id, Integer, required: false
|
6
|
+
end
|
7
|
+
|
8
|
+
field :not_null_invoice, InvoiceType, null: false do
|
9
|
+
description 'Find invoice'
|
10
|
+
argument :id, Integer, required: false
|
11
|
+
end
|
12
|
+
|
13
|
+
def invoice(id: nil)
|
14
|
+
return nil if id.nil?
|
15
|
+
OpenStruct.new(
|
16
|
+
id: id,
|
17
|
+
fee_in_cents: 20_000
|
18
|
+
)
|
19
|
+
end
|
3
20
|
|
4
|
-
|
5
|
-
|
6
|
-
description 'Find Invoices'
|
7
|
-
resolve ->(_obj, args, _ctx) {
|
8
|
-
(args[:ids] || []).map do |id|
|
9
|
-
OpenStruct.new(
|
10
|
-
id: id,
|
11
|
-
fee_in_cents: 20_000
|
12
|
-
)
|
13
|
-
end
|
14
|
-
}
|
21
|
+
def not_null_invoice(*)
|
22
|
+
nil
|
15
23
|
end
|
16
24
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
-
InvoiceType
|
2
|
-
name 'Invoice'
|
1
|
+
class InvoiceType < GraphQL::Schema::Object
|
3
2
|
description 'An Invoice'
|
4
|
-
|
5
|
-
|
3
|
+
graphql_name 'Invoice'
|
4
|
+
|
5
|
+
field :id, ID, null: false
|
6
|
+
field :fee_in_cents, Integer, null: true
|
6
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphlient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -103,10 +103,10 @@ files:
|
|
103
103
|
- spec/support/context/dummy_client.rb
|
104
104
|
- spec/support/dummy_app.rb
|
105
105
|
- spec/support/dummy_schema.rb
|
106
|
-
- spec/support/mutations/
|
107
|
-
- spec/support/mutations/mutation.rb
|
106
|
+
- spec/support/mutations/create_invoice.rb
|
108
107
|
- spec/support/queries/query.rb
|
109
108
|
- spec/support/types/invoice_type.rb
|
109
|
+
- spec/support/types/mutation_type.rb
|
110
110
|
homepage: http://github.com/ashkan18/graphlient
|
111
111
|
licenses:
|
112
112
|
- MIT
|
@@ -1,16 +0,0 @@
|
|
1
|
-
CreateInvoiceMutation = GraphQL::Relay::Mutation.define do
|
2
|
-
name 'createInvoice'
|
3
|
-
|
4
|
-
input_field :fee_in_cents, !types.Int
|
5
|
-
|
6
|
-
return_type types[InvoiceType]
|
7
|
-
|
8
|
-
resolve ->(_object, inputs, _ctx) {
|
9
|
-
[
|
10
|
-
OpenStruct.new(
|
11
|
-
id: 1231,
|
12
|
-
fee_in_cents: inputs[:fee_in_cents]
|
13
|
-
)
|
14
|
-
]
|
15
|
-
}
|
16
|
-
end
|