hq-graphql 1.1.1 → 1.1.2
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 +5 -5
- data/README.md +21 -1
- data/lib/hq/graphql/input_object.rb +12 -1
- data/lib/hq/graphql/resource.rb +63 -16
- data/lib/hq/graphql/root_query.rb +2 -13
- data/lib/hq/graphql/types.rb +1 -0
- data/lib/hq/graphql/version.rb +1 -1
- metadata +6 -46
- data/spec/factories/advisors.rb +0 -6
- data/spec/factories/organizations.rb +0 -5
- data/spec/factories/users.rb +0 -6
- data/spec/internal/app/models/advisor.rb +0 -3
- data/spec/internal/app/models/organization.rb +0 -3
- data/spec/internal/app/models/test_type.rb +0 -1
- data/spec/internal/app/models/user.rb +0 -3
- data/spec/internal/config/database.circleci.yml +0 -24
- data/spec/internal/config/database.yml +0 -8
- data/spec/internal/db/schema.rb +0 -30
- data/spec/lib/graphql/active_record_extensions_spec.rb +0 -63
- data/spec/lib/graphql/input_object_spec.rb +0 -173
- data/spec/lib/graphql/inputs_spec.rb +0 -40
- data/spec/lib/graphql/object_spec.rb +0 -173
- data/spec/lib/graphql/resource_spec.rb +0 -392
- data/spec/lib/graphql/types/object_spec.rb +0 -96
- data/spec/lib/graphql/types/uuid_spec.rb +0 -65
- data/spec/lib/graphql/types_spec.rb +0 -86
- data/spec/rails_helper.rb +0 -43
- data/spec/spec_helper.rb +0 -22
@@ -1,392 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe ::HQ::GraphQL::Resource do
|
4
|
-
let(:organization_type) do
|
5
|
-
Class.new do
|
6
|
-
include ::HQ::GraphQL::Resource
|
7
|
-
self.model_name = "Organization"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:advisor_type) do
|
12
|
-
Class.new do
|
13
|
-
include ::HQ::GraphQL::Resource
|
14
|
-
self.model_name = "Advisor"
|
15
|
-
|
16
|
-
root_query
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:root_query) do
|
21
|
-
Class.new(::HQ::GraphQL::RootQuery)
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:root_mutation) do
|
25
|
-
Class.new(::HQ::GraphQL::RootMutation)
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:schema) do
|
29
|
-
Class.new(GraphQL::Schema) do
|
30
|
-
query(RootQuery)
|
31
|
-
mutation(RootMutation)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
before(:each) do
|
36
|
-
advisor_type
|
37
|
-
stub_const("RootQuery", root_query)
|
38
|
-
stub_const("RootMutation", root_mutation)
|
39
|
-
end
|
40
|
-
|
41
|
-
context "defaults" do
|
42
|
-
it "builds the query klass" do
|
43
|
-
expect(::HQ::GraphQL::Types[Advisor]).to eql(advisor_type.query_klass)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "builds the input klass" do
|
47
|
-
expect(::HQ::GraphQL::Inputs[Advisor]).to eql(advisor_type.input_klass)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "creates query fields" do
|
51
|
-
::HQ::GraphQL::Types[Advisor].graphql_definition
|
52
|
-
expected = ["id", "organizationId", "name", "createdAt", "updatedAt"]
|
53
|
-
expect(::HQ::GraphQL::Types[Advisor].fields.keys).to contain_exactly(*expected)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "creates query graphql name" do
|
57
|
-
::HQ::GraphQL::Types[Advisor].graphql_definition
|
58
|
-
expect(::HQ::GraphQL::Types[Advisor].graphql_name).to eql("Advisor")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "creates input arguments" do
|
62
|
-
::HQ::GraphQL::Inputs[Advisor].graphql_definition
|
63
|
-
expected = ["id", "organizationId", "name", "createdAt", "updatedAt"]
|
64
|
-
expect(::HQ::GraphQL::Inputs[Advisor].arguments.keys).to contain_exactly(*expected)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "creates input graphql name" do
|
68
|
-
::HQ::GraphQL::Inputs[Advisor].graphql_definition
|
69
|
-
expect(::HQ::GraphQL::Inputs[Advisor].graphql_name).to eql("AdvisorInput")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "doesn't create mutations" do
|
73
|
-
expect(advisor_type.mutation_klasses).to be_empty
|
74
|
-
end
|
75
|
-
|
76
|
-
context "with an association" do
|
77
|
-
before(:each) do
|
78
|
-
organization_type
|
79
|
-
end
|
80
|
-
|
81
|
-
it "adds organization type" do
|
82
|
-
::HQ::GraphQL::Types[Advisor].graphql_definition
|
83
|
-
expected = ["id", "organization", "organizationId", "name", "createdAt", "updatedAt"]
|
84
|
-
expect(::HQ::GraphQL::Types[Advisor].fields.keys).to contain_exactly(*expected)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "doesn't add organization type" do
|
88
|
-
::HQ::GraphQL::Inputs[Advisor].graphql_definition
|
89
|
-
expected = ["id", "organizationId", "name", "createdAt", "updatedAt"]
|
90
|
-
expect(::HQ::GraphQL::Inputs[Advisor].arguments.keys).to contain_exactly(*expected)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context ".query" do
|
96
|
-
let(:advisor_type) do
|
97
|
-
Class.new do
|
98
|
-
include ::HQ::GraphQL::Resource
|
99
|
-
self.model_name = "Advisor"
|
100
|
-
|
101
|
-
query associations: false do
|
102
|
-
graphql_name "CustomAdvisorName"
|
103
|
-
remove_attr :name
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
before(:each) do
|
109
|
-
organization_type
|
110
|
-
advisor_type
|
111
|
-
end
|
112
|
-
|
113
|
-
it "removes name" do
|
114
|
-
::HQ::GraphQL::Types[Advisor].graphql_definition
|
115
|
-
expected = ["id", "organizationId", "createdAt", "updatedAt"]
|
116
|
-
expect(::HQ::GraphQL::Types[Advisor].fields.keys).to contain_exactly(*expected)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "customizes graphql name" do
|
120
|
-
::HQ::GraphQL::Types[Advisor].graphql_definition
|
121
|
-
expect(::HQ::GraphQL::Types[Advisor].graphql_name).to eql("CustomAdvisorName")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context ".input" do
|
126
|
-
let(:advisor_type) do
|
127
|
-
Class.new do
|
128
|
-
include ::HQ::GraphQL::Resource
|
129
|
-
self.model_name = "Advisor"
|
130
|
-
|
131
|
-
input do
|
132
|
-
graphql_name "CustomAdvisorInput"
|
133
|
-
remove_attr :name
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
before(:each) do
|
139
|
-
organization_type
|
140
|
-
advisor_type
|
141
|
-
end
|
142
|
-
|
143
|
-
it "removes name" do
|
144
|
-
::HQ::GraphQL::Inputs[Advisor].graphql_definition
|
145
|
-
expected = ["id", "organizationId", "createdAt", "updatedAt"]
|
146
|
-
expect(::HQ::GraphQL::Inputs[Advisor].arguments.keys).to contain_exactly(*expected)
|
147
|
-
end
|
148
|
-
|
149
|
-
it "customizes graphql name" do
|
150
|
-
::HQ::GraphQL::Inputs[Advisor].graphql_definition
|
151
|
-
expect(::HQ::GraphQL::Inputs[Advisor].graphql_name).to eql("CustomAdvisorInput")
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context ".mutations" do
|
156
|
-
let(:advisor_type) do
|
157
|
-
Class.new do
|
158
|
-
include ::HQ::GraphQL::Resource
|
159
|
-
self.model_name = "Advisor"
|
160
|
-
|
161
|
-
mutations
|
162
|
-
|
163
|
-
input do
|
164
|
-
remove_attr :name
|
165
|
-
add_association :organization
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
before(:each) do
|
171
|
-
organization_type
|
172
|
-
end
|
173
|
-
|
174
|
-
it "generates the create, update, and destroy mutations by default" do
|
175
|
-
expect(advisor_type.mutation_klasses.keys).to contain_exactly("create_advisor", "update_advisor", "destroy_advisor")
|
176
|
-
end
|
177
|
-
|
178
|
-
it "removes name on update" do
|
179
|
-
update_mutation = advisor_type.mutation_klasses[:update_advisor]
|
180
|
-
update_mutation.payload_type
|
181
|
-
|
182
|
-
input_object = advisor_type.input_klass
|
183
|
-
input_object.graphql_definition
|
184
|
-
|
185
|
-
aggregate_failures do
|
186
|
-
expected_arguments = ["id", "organizationId", "organization", "createdAt", "updatedAt"]
|
187
|
-
expect(input_object.arguments.keys).to contain_exactly(*expected_arguments)
|
188
|
-
|
189
|
-
expected_arguments = ["id", "attributes"]
|
190
|
-
expect(update_mutation.arguments.keys).to contain_exactly(*expected_arguments)
|
191
|
-
|
192
|
-
expected_fields = ["errors", "resource"]
|
193
|
-
expect(update_mutation.fields.keys).to contain_exactly(*expected_fields)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context "execution" do
|
199
|
-
let(:find_advisor) {
|
200
|
-
<<-gql
|
201
|
-
query findAdvisor($id: UUID!){
|
202
|
-
advisor(id: $id) {
|
203
|
-
name
|
204
|
-
organizationId
|
205
|
-
|
206
|
-
organization {
|
207
|
-
name
|
208
|
-
}
|
209
|
-
}
|
210
|
-
}
|
211
|
-
gql
|
212
|
-
}
|
213
|
-
|
214
|
-
let(:create_mutation) {
|
215
|
-
<<-gql
|
216
|
-
mutation createAdvisor($attributes: AdvisorInput!){
|
217
|
-
createAdvisor(attributes: $attributes) {
|
218
|
-
errors
|
219
|
-
resource {
|
220
|
-
id
|
221
|
-
name
|
222
|
-
}
|
223
|
-
}
|
224
|
-
}
|
225
|
-
gql
|
226
|
-
}
|
227
|
-
|
228
|
-
let(:update_mutation) {
|
229
|
-
<<-gql
|
230
|
-
mutation updateAdvisor($id: UUID!, $attributes: AdvisorInput!){
|
231
|
-
updateAdvisor(id: $id, attributes: $attributes) {
|
232
|
-
errors
|
233
|
-
resource {
|
234
|
-
name
|
235
|
-
organization {
|
236
|
-
name
|
237
|
-
}
|
238
|
-
}
|
239
|
-
}
|
240
|
-
}
|
241
|
-
gql
|
242
|
-
}
|
243
|
-
|
244
|
-
let(:destroy_mutation) {
|
245
|
-
<<-gql
|
246
|
-
mutation destroyAdvisor($id: UUID!){
|
247
|
-
destroyAdvisor(id: $id) {
|
248
|
-
errors
|
249
|
-
resource {
|
250
|
-
name
|
251
|
-
}
|
252
|
-
}
|
253
|
-
}
|
254
|
-
gql
|
255
|
-
}
|
256
|
-
|
257
|
-
before(:each) do
|
258
|
-
organization_type
|
259
|
-
|
260
|
-
advisor_type.class_eval do
|
261
|
-
mutations
|
262
|
-
|
263
|
-
input do
|
264
|
-
add_association :organization
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
it "fetches results" do
|
270
|
-
advisor = FactoryBot.create(:advisor)
|
271
|
-
results = schema.execute(find_advisor, variables: { id: advisor.id })
|
272
|
-
data = results["data"]["advisor"]
|
273
|
-
|
274
|
-
aggregate_failures do
|
275
|
-
expect(data["name"]).to eql(advisor.name)
|
276
|
-
expect(data["organizationId"]).to eql(advisor.organization_id)
|
277
|
-
expect(data["organization"]["name"]).to eql(advisor.organization.name)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
it "creates" do
|
282
|
-
organization = FactoryBot.create(:organization)
|
283
|
-
name = "Bob"
|
284
|
-
results = schema.execute(create_mutation, variables: { attributes: { name: name, organizationId: organization.id } })
|
285
|
-
|
286
|
-
data = results["data"]
|
287
|
-
aggregate_failures do
|
288
|
-
expect(data["errors"]).to be_nil
|
289
|
-
expect(data["createAdvisor"]["resource"]["name"]).to eql name
|
290
|
-
expect(Advisor.where(id: data["createAdvisor"]["resource"]["id"]).exists?).to eql true
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
it "updates" do
|
295
|
-
advisor = FactoryBot.create(:advisor)
|
296
|
-
name = "Bob"
|
297
|
-
organization_name = "Foo"
|
298
|
-
|
299
|
-
results = schema.execute(update_mutation, variables: {
|
300
|
-
id: advisor.id,
|
301
|
-
attributes: {
|
302
|
-
name: name,
|
303
|
-
organization: { id: advisor.organization_id, name: organization_name }
|
304
|
-
}
|
305
|
-
})
|
306
|
-
|
307
|
-
data = results["data"]
|
308
|
-
aggregate_failures do
|
309
|
-
expect(data["errors"]).to be_nil
|
310
|
-
expect(data["updateAdvisor"]["resource"]["name"]).to eql name
|
311
|
-
expect(data["updateAdvisor"]["resource"]["organization"]["name"]).to eql organization_name
|
312
|
-
expect(Advisor.find(advisor.id).name).to eql name
|
313
|
-
expect(Organization.find(advisor.organization_id).name).to eql organization_name
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
it "destroys" do
|
318
|
-
advisor = FactoryBot.create(:advisor)
|
319
|
-
results = schema.execute(destroy_mutation, variables: { id: advisor.id })
|
320
|
-
|
321
|
-
data = results["data"]
|
322
|
-
aggregate_failures do
|
323
|
-
expect(data["errors"]).to be_nil
|
324
|
-
expect(data["destroyAdvisor"]["resource"]["name"]).to eql advisor.name
|
325
|
-
expect(Advisor.where(id: advisor.id).exists?).to eql false
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
context "with a global scope" do
|
330
|
-
before(:each) do
|
331
|
-
allow(::HQ::GraphQL).to receive(:default_scope) { Advisor.none }
|
332
|
-
end
|
333
|
-
|
334
|
-
it "returns nothing" do
|
335
|
-
advisor = FactoryBot.create(:advisor)
|
336
|
-
results = schema.execute(find_advisor, variables: { id: advisor.id })
|
337
|
-
|
338
|
-
expect(results["data"]["advisor"]).to be_nil
|
339
|
-
end
|
340
|
-
|
341
|
-
it "returns an error on a mutation" do
|
342
|
-
advisor = FactoryBot.create(:advisor)
|
343
|
-
results = schema.execute(update_mutation, variables: {
|
344
|
-
id: advisor.id,
|
345
|
-
attributes: {
|
346
|
-
name: "Bob"
|
347
|
-
}
|
348
|
-
})
|
349
|
-
|
350
|
-
data = results["data"]
|
351
|
-
aggregate_failures do
|
352
|
-
expect(data["updateAdvisor"]["errors"]).to be_present
|
353
|
-
expect(data["updateAdvisor"]["resource"]).to be_nil
|
354
|
-
end
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
context "with a local scope" do
|
359
|
-
before(:each) do
|
360
|
-
advisor_type.class_eval do
|
361
|
-
default_scope do
|
362
|
-
Advisor.none
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
it "returns nothing" do
|
368
|
-
advisor = FactoryBot.create(:advisor)
|
369
|
-
results = schema.execute(find_advisor, variables: { id: advisor.id })
|
370
|
-
|
371
|
-
expect(results["data"]["advisor"]).to be_nil
|
372
|
-
end
|
373
|
-
|
374
|
-
it "returns an error on a mutation" do
|
375
|
-
advisor = FactoryBot.create(:advisor)
|
376
|
-
results = schema.execute(update_mutation, variables: {
|
377
|
-
id: advisor.id,
|
378
|
-
attributes: {
|
379
|
-
name: "Bob"
|
380
|
-
}
|
381
|
-
})
|
382
|
-
|
383
|
-
data = results["data"]
|
384
|
-
aggregate_failures do
|
385
|
-
expect(data["updateAdvisor"]["errors"]).to be_present
|
386
|
-
expect(data["updateAdvisor"]["resource"]).to be_nil
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe ::HQ::GraphQL::Types::Object do
|
4
|
-
let(:hql_object_klass) do
|
5
|
-
Class.new(::HQ::GraphQL::Object) do
|
6
|
-
graphql_name "TestQuery"
|
7
|
-
|
8
|
-
field :valid_object, ::HQ::GraphQL::Types::Object, null: false
|
9
|
-
field :invalid_object, ::HQ::GraphQL::Types::Object, null: false
|
10
|
-
|
11
|
-
def valid_object
|
12
|
-
{ name: object.name }
|
13
|
-
end
|
14
|
-
|
15
|
-
def invalid_object
|
16
|
-
:not_an_object
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:query) do
|
22
|
-
Class.new(::HQ::GraphQL::Object) do
|
23
|
-
graphql_name "Query"
|
24
|
-
|
25
|
-
field :advisor, AdvisorType, null: false do
|
26
|
-
argument :filters, ::HQ::GraphQL::Types::Object, required: true
|
27
|
-
end
|
28
|
-
|
29
|
-
def advisor(filters:)
|
30
|
-
Advisor.find_by(filters)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
let(:schema) do
|
36
|
-
Class.new(GraphQL::Schema) do
|
37
|
-
query(Query)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
let(:query_str) do
|
42
|
-
<<-gql
|
43
|
-
query findAdvisor($filters: Object!){
|
44
|
-
advisor(filters: $filters) {
|
45
|
-
validObject
|
46
|
-
}
|
47
|
-
}
|
48
|
-
gql
|
49
|
-
end
|
50
|
-
|
51
|
-
let(:invalid_query_str) do
|
52
|
-
<<-gql
|
53
|
-
query findAdvisor($filters: Object!){
|
54
|
-
advisor(filters: $filters) {
|
55
|
-
invalidObject
|
56
|
-
}
|
57
|
-
}
|
58
|
-
gql
|
59
|
-
end
|
60
|
-
|
61
|
-
let(:advisor) { FactoryBot.create(:advisor) }
|
62
|
-
let(:advisor_filter) { { name: advisor.name } }
|
63
|
-
|
64
|
-
before(:each) do
|
65
|
-
stub_const("AdvisorType", hql_object_klass)
|
66
|
-
stub_const("Query", query)
|
67
|
-
end
|
68
|
-
|
69
|
-
describe ".coerce_result" do
|
70
|
-
it "returns an object" do
|
71
|
-
results = schema.execute(query_str, variables: { filters: advisor_filter })
|
72
|
-
expect(results["data"]["advisor"]["validObject"]).to eql({ name: advisor.name })
|
73
|
-
end
|
74
|
-
|
75
|
-
it "raises an error when returning am invalid object " do
|
76
|
-
expect { schema.execute(invalid_query_str, variables: { filters: advisor_filter }) }.to raise_error(
|
77
|
-
::GraphQL::CoercionError, ":not_an_object is not a valid Object"
|
78
|
-
)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe ".coerce_input" do
|
83
|
-
it "accepts an object as input" do
|
84
|
-
result = schema.execute(query_str, variables: { filters: advisor_filter })
|
85
|
-
expect(result["data"]["advisor"]["validObject"]).to eql({ name: advisor.name })
|
86
|
-
end
|
87
|
-
|
88
|
-
it "raises an error when an argument is an invalid object" do
|
89
|
-
result = schema.execute(query_str, variables: { filters: advisor.name })
|
90
|
-
aggregate_failures do
|
91
|
-
expect(result["errors"].length).to eql(1)
|
92
|
-
expect(result["errors"][0]["message"]).to eql("Variable filters of type Object! was provided invalid value")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe ::HQ::GraphQL::Types::UUID do
|
4
|
-
let(:hql_object_klass) do
|
5
|
-
Class.new(::HQ::GraphQL::Object) do
|
6
|
-
graphql_name "TestQuery"
|
7
|
-
|
8
|
-
field :name, ::HQ::GraphQL::Types::UUID, null: false
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:query) do
|
13
|
-
Class.new(::HQ::GraphQL::Object) do
|
14
|
-
graphql_name "Query"
|
15
|
-
|
16
|
-
field :advisor, AdvisorType, null: false do
|
17
|
-
argument :id, ::HQ::GraphQL::Types::UUID, required: true
|
18
|
-
end
|
19
|
-
|
20
|
-
def advisor(id:)
|
21
|
-
Advisor.find(id)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:schema) do
|
27
|
-
Class.new(GraphQL::Schema) do
|
28
|
-
query(Query)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
let(:query_str) do
|
33
|
-
<<-gql
|
34
|
-
query findAdvisor($id: UUID!){
|
35
|
-
advisor(id: $id) {
|
36
|
-
name
|
37
|
-
}
|
38
|
-
}
|
39
|
-
gql
|
40
|
-
end
|
41
|
-
|
42
|
-
before(:each) do
|
43
|
-
stub_const("AdvisorType", hql_object_klass)
|
44
|
-
stub_const("Query", query)
|
45
|
-
end
|
46
|
-
|
47
|
-
describe ".coerce_result" do
|
48
|
-
it "raises an error on incorrect type" do
|
49
|
-
advisor = FactoryBot.create(:advisor)
|
50
|
-
expect { schema.execute(query_str, variables: { id: advisor.id }) }.to raise_error(
|
51
|
-
::GraphQL::CoercionError, "\"#{advisor.name}\" is not a valid UUID"
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe ".coerce_input" do
|
57
|
-
it "displays an error message" do
|
58
|
-
result = schema.execute(query_str, variables: { id: "1" })
|
59
|
-
aggregate_failures do
|
60
|
-
expect(result["errors"].length).to eql(1)
|
61
|
-
expect(result["errors"][0]["message"]).to eql("Variable id of type UUID! was provided invalid value")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe ::HQ::GraphQL::Types do
|
4
|
-
|
5
|
-
describe ".[]" do
|
6
|
-
let(:graphql_klass) do
|
7
|
-
Class.new do
|
8
|
-
include ::HQ::GraphQL::Resource
|
9
|
-
|
10
|
-
self.model_name = "Advisor"
|
11
|
-
|
12
|
-
query(attributes: false, associations: false) do
|
13
|
-
field :custom_field, String, null: false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "finds the type" do
|
19
|
-
type_object = graphql_klass.query_klass
|
20
|
-
|
21
|
-
aggregate_failures do
|
22
|
-
expect(type_object.superclass).to eql(::HQ::GraphQL::Object)
|
23
|
-
expect(type_object).to eql(described_class[Advisor])
|
24
|
-
expect(type_object.fields.keys).to contain_exactly("customField")
|
25
|
-
type_object.to_graphql
|
26
|
-
expect(type_object.fields.keys).to contain_exactly("customField")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "finds the type when lookup is a string" do
|
31
|
-
type_object = graphql_klass.query_klass
|
32
|
-
expect(type_object).to eql(described_class["Advisor"])
|
33
|
-
end
|
34
|
-
|
35
|
-
it "raises an exception for unknown types" do
|
36
|
-
expect { described_class[Advisor] }.to raise_error(described_class::Error)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe ".type_from_column" do
|
41
|
-
context "UUID" do
|
42
|
-
it "matches uuid" do
|
43
|
-
expect(type_from_column("id")).to eq ::HQ::GraphQL::Types::UUID
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "Object" do
|
48
|
-
it "matches json" do
|
49
|
-
expect(type_from_column("data_json")).to eq ::HQ::GraphQL::Types::Object
|
50
|
-
end
|
51
|
-
|
52
|
-
it "matches jsonb" do
|
53
|
-
expect(type_from_column("data_jsonb")).to eq ::HQ::GraphQL::Types::Object
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "Int" do
|
58
|
-
it "matches integer" do
|
59
|
-
expect(type_from_column("count")).to eq ::GraphQL::Types::Int
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "Float" do
|
64
|
-
it "matches decimal" do
|
65
|
-
expect(type_from_column("amount")).to eq ::GraphQL::Types::Float
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "Boolean" do
|
70
|
-
it "matches boolean" do
|
71
|
-
expect(type_from_column("is_bool")).to eq ::GraphQL::Types::Boolean
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "String" do
|
76
|
-
it "matches string" do
|
77
|
-
expect(type_from_column("name")).to eq ::GraphQL::Types::String
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def type_from_column(name)
|
82
|
-
described_class.type_from_column(TestType.columns_hash[name])
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
data/spec/rails_helper.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require "testhq/coverage" # Needs to be require at the top of this file!
|
2
|
-
# Coverage must also be enabled in the environment by setting
|
3
|
-
# environment variables, e.g. `COVERAGE=true` or `CODECLIMATE_REPO_TOKEN=...`.
|
4
|
-
# See https://github.com/OneHQ/testhq#code-coverage.
|
5
|
-
|
6
|
-
require "bundler/setup"
|
7
|
-
require "combustion"
|
8
|
-
|
9
|
-
silence_stream(STDOUT) do # Hides a lot of output from Combustion init such as schema loading.
|
10
|
-
Combustion.initialize! :all do
|
11
|
-
# Disable strong parameters
|
12
|
-
config.action_controller.permit_all_parameters = true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
require "byebug"
|
17
|
-
require "rspec/rails"
|
18
|
-
require "testhq"
|
19
|
-
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.expect_with :rspec do |c|
|
22
|
-
c.syntax = [:expect]
|
23
|
-
end
|
24
|
-
|
25
|
-
config.use_transactional_fixtures = false
|
26
|
-
|
27
|
-
config.include FactoryBot::Syntax::Methods
|
28
|
-
|
29
|
-
config.before(:suite) do
|
30
|
-
DatabaseCleaner.strategy = :transaction
|
31
|
-
DatabaseCleaner.clean_with :truncation # Clear everything
|
32
|
-
end
|
33
|
-
|
34
|
-
config.before(:each) do
|
35
|
-
::HQ::GraphQL.reset!
|
36
|
-
DatabaseCleaner.start
|
37
|
-
end
|
38
|
-
|
39
|
-
config.after(:each) do
|
40
|
-
DatabaseCleaner.clean
|
41
|
-
::HQ::GraphQL.reset!
|
42
|
-
end
|
43
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
RSpec.configure do |config|
|
2
|
-
config.expect_with :rspec do |expectations|
|
3
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
4
|
-
# and `failure_message` of custom matchers include text for helper methods
|
5
|
-
# defined using `chain`, e.g.:
|
6
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
7
|
-
# # => "be bigger than 2 and smaller than 4"
|
8
|
-
# ...rather than:
|
9
|
-
# # => "be bigger than 2"
|
10
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
11
|
-
end
|
12
|
-
|
13
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
14
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
15
|
-
config.mock_with :rspec do |mocks|
|
16
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
17
|
-
# a real object. This is generally recommended, and will default to
|
18
|
-
# `true` in RSpec 4.
|
19
|
-
mocks.verify_partial_doubles = true
|
20
|
-
end
|
21
|
-
config.order = :random
|
22
|
-
end
|