hq-graphql 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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,173 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe ::HQ::GraphQL::InputObject do
|
4
|
-
|
5
|
-
describe ".with_model" do
|
6
|
-
let(:hq_input_object) do
|
7
|
-
Class.new(described_class) do
|
8
|
-
graphql_name "TestQuery"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:organization_type) do
|
13
|
-
Class.new do
|
14
|
-
include ::HQ::GraphQL::Resource
|
15
|
-
|
16
|
-
self.model_name = "Organization"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
organization_type
|
22
|
-
end
|
23
|
-
|
24
|
-
it "adds everything by default" do
|
25
|
-
hq_input_object.class_eval do
|
26
|
-
with_model "Advisor"
|
27
|
-
end
|
28
|
-
|
29
|
-
expect(hq_input_object.arguments.keys).to be_empty
|
30
|
-
hq_input_object.graphql_definition
|
31
|
-
expected = ["createdAt", "id", "name", "organizationId", "updatedAt"]
|
32
|
-
expect(hq_input_object.arguments.keys).to contain_exactly(*expected)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".remove_attributes" do
|
36
|
-
it "removes an attribute" do
|
37
|
-
hq_input_object.class_eval do
|
38
|
-
remove_attributes :created_at, :id, :organization_id
|
39
|
-
with_model "Advisor"
|
40
|
-
end
|
41
|
-
|
42
|
-
expect(hq_input_object.arguments.keys).to be_empty
|
43
|
-
hq_input_object.graphql_definition
|
44
|
-
expected = ["name", "updatedAt"]
|
45
|
-
expect(hq_input_object.arguments.keys).to contain_exactly(*expected)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "raises an error when trying to remove a column that doesn't exist" do
|
49
|
-
hq_input_object.class_eval do
|
50
|
-
remove_attributes :doesnt_exist
|
51
|
-
with_model "Advisor"
|
52
|
-
end
|
53
|
-
|
54
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raises an error when not connected to a model" do
|
58
|
-
hq_input_object.class_eval do
|
59
|
-
remove_attributes :created_at
|
60
|
-
end
|
61
|
-
|
62
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe ".remove_associations" do
|
67
|
-
it "removes an association" do
|
68
|
-
hq_input_object.class_eval do
|
69
|
-
remove_associations :organization
|
70
|
-
with_model "Advisor"
|
71
|
-
end
|
72
|
-
|
73
|
-
expect(hq_input_object.arguments.keys).to be_empty
|
74
|
-
hq_input_object.graphql_definition
|
75
|
-
expected = ["createdAt", "id", "name", "organizationId", "updatedAt"]
|
76
|
-
expect(hq_input_object.arguments.keys).to contain_exactly(*expected)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "raises an error when trying to remove a column that doesn't exist" do
|
80
|
-
hq_input_object.class_eval do
|
81
|
-
remove_associations :doesnt_exist
|
82
|
-
with_model "Advisor"
|
83
|
-
end
|
84
|
-
|
85
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "raises an error when not connected to a model" do
|
89
|
-
hq_input_object.class_eval do
|
90
|
-
remove_associations :organization
|
91
|
-
end
|
92
|
-
|
93
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "with attributes and associations turned off" do
|
98
|
-
it "doesn't have any arguments by default" do
|
99
|
-
hq_input_object.graphql_definition
|
100
|
-
expect(hq_input_object.arguments.keys).to be_empty
|
101
|
-
end
|
102
|
-
|
103
|
-
it "doesn't have any arguments when disabling model attrs/associations" do
|
104
|
-
hq_input_object.class_eval do
|
105
|
-
with_model "Advisor", attributes: false, associations: false
|
106
|
-
end
|
107
|
-
hq_input_object.graphql_definition
|
108
|
-
expect(hq_input_object.arguments.keys).to be_empty
|
109
|
-
end
|
110
|
-
|
111
|
-
describe ".add_attributes" do
|
112
|
-
it "adds attributes" do
|
113
|
-
hq_input_object.class_eval do
|
114
|
-
add_attributes :name
|
115
|
-
with_model "Advisor", attributes: false, associations: false
|
116
|
-
end
|
117
|
-
|
118
|
-
expect(hq_input_object.arguments.keys).to be_empty
|
119
|
-
hq_input_object.graphql_definition
|
120
|
-
expect(hq_input_object.arguments.keys).to contain_exactly("name")
|
121
|
-
end
|
122
|
-
|
123
|
-
it "raises an error when adding an attribute that doesn't exist" do
|
124
|
-
hq_input_object.class_eval do
|
125
|
-
add_attributes :doesnt_exist
|
126
|
-
with_model "Advisor", attributes: false, associations: false
|
127
|
-
end
|
128
|
-
|
129
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "raises an error when not connected to a model" do
|
133
|
-
hq_input_object.class_eval do
|
134
|
-
add_attributes :name
|
135
|
-
end
|
136
|
-
|
137
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe ".add_associations" do
|
142
|
-
it "adds associations" do
|
143
|
-
hq_input_object.class_eval do
|
144
|
-
add_associations :organization
|
145
|
-
with_model "Advisor", attributes: false, associations: false
|
146
|
-
end
|
147
|
-
|
148
|
-
expect(hq_input_object.arguments.keys).to be_empty
|
149
|
-
hq_input_object.graphql_definition
|
150
|
-
expect(hq_input_object.arguments.keys).to contain_exactly("organization")
|
151
|
-
end
|
152
|
-
|
153
|
-
it "raises an error when adding an association that doesn't exist" do
|
154
|
-
hq_input_object.class_eval do
|
155
|
-
add_associations :doesnt_exist
|
156
|
-
with_model "Advisor", attributes: false, associations: false
|
157
|
-
end
|
158
|
-
|
159
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "raises an error when not connected to a model" do
|
163
|
-
hq_input_object.class_eval do
|
164
|
-
add_associations :organization
|
165
|
-
end
|
166
|
-
|
167
|
-
expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe ::HQ::GraphQL::Inputs 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
|
-
input(attributes: false, associations: false) do
|
13
|
-
argument :customField, String, "Header for the post", required: true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "finds the type" do
|
19
|
-
input_object = graphql_klass.input_klass
|
20
|
-
|
21
|
-
aggregate_failures do
|
22
|
-
expect(input_object.superclass).to eql(::HQ::GraphQL::InputObject)
|
23
|
-
expect(input_object).to eql(described_class[Advisor])
|
24
|
-
expect(input_object.arguments.keys).to contain_exactly("customField")
|
25
|
-
input_object.to_graphql
|
26
|
-
expect(input_object.arguments.keys).to contain_exactly("customField")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "finds the type when lookup is a string" do
|
31
|
-
input_object = graphql_klass.input_klass
|
32
|
-
expect(input_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
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe ::HQ::GraphQL::Object do
|
4
|
-
|
5
|
-
describe ".with_model" do
|
6
|
-
let(:hq_object) do
|
7
|
-
Class.new(described_class) do
|
8
|
-
graphql_name "TestQuery"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:organization_type) do
|
13
|
-
Class.new do
|
14
|
-
include ::HQ::GraphQL::Resource
|
15
|
-
|
16
|
-
self.model_name = "Organization"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
organization_type
|
22
|
-
end
|
23
|
-
|
24
|
-
it "adds everything by default" do
|
25
|
-
hq_object.class_eval do
|
26
|
-
with_model "Advisor"
|
27
|
-
end
|
28
|
-
|
29
|
-
expect(hq_object.fields.keys).to be_empty
|
30
|
-
hq_object.graphql_definition
|
31
|
-
expected = ["createdAt", "id", "name", "organization", "organizationId", "updatedAt"]
|
32
|
-
expect(hq_object.fields.keys).to contain_exactly(*expected)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".remove_attributes" do
|
36
|
-
it "removes an attribute" do
|
37
|
-
hq_object.class_eval do
|
38
|
-
remove_attributes :created_at, :id, :organization_id
|
39
|
-
with_model "Advisor"
|
40
|
-
end
|
41
|
-
|
42
|
-
expect(hq_object.fields.keys).to be_empty
|
43
|
-
hq_object.graphql_definition
|
44
|
-
expected = ["name", "organization", "updatedAt"]
|
45
|
-
expect(hq_object.fields.keys).to contain_exactly(*expected)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "raises an error when trying to remove a column that doesn't exist" do
|
49
|
-
hq_object.class_eval do
|
50
|
-
remove_attributes :doesnt_exist
|
51
|
-
with_model "Advisor"
|
52
|
-
end
|
53
|
-
|
54
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raises an error when not connected to a model" do
|
58
|
-
hq_object.class_eval do
|
59
|
-
remove_attributes :created_at
|
60
|
-
end
|
61
|
-
|
62
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe ".remove_associations" do
|
67
|
-
it "removes an association" do
|
68
|
-
hq_object.class_eval do
|
69
|
-
remove_associations :organization
|
70
|
-
with_model "Advisor"
|
71
|
-
end
|
72
|
-
|
73
|
-
expect(hq_object.fields.keys).to be_empty
|
74
|
-
hq_object.graphql_definition
|
75
|
-
expected = ["createdAt", "id", "name", "organizationId", "updatedAt"]
|
76
|
-
expect(hq_object.fields.keys).to contain_exactly(*expected)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "raises an error when trying to remove a column that doesn't exist" do
|
80
|
-
hq_object.class_eval do
|
81
|
-
remove_associations :doesnt_exist
|
82
|
-
with_model "Advisor"
|
83
|
-
end
|
84
|
-
|
85
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "raises an error when not connected to a model" do
|
89
|
-
hq_object.class_eval do
|
90
|
-
remove_associations :organization
|
91
|
-
end
|
92
|
-
|
93
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "with attributes and associations turned off" do
|
98
|
-
it "doesn't have any fields by default" do
|
99
|
-
hq_object.graphql_definition
|
100
|
-
expect(hq_object.fields.keys).to be_empty
|
101
|
-
end
|
102
|
-
|
103
|
-
it "doesn't have any fields when disabling model attrs/associations" do
|
104
|
-
hq_object.class_eval do
|
105
|
-
with_model "Advisor", attributes: false, associations: false
|
106
|
-
end
|
107
|
-
hq_object.graphql_definition
|
108
|
-
expect(hq_object.fields.keys).to be_empty
|
109
|
-
end
|
110
|
-
|
111
|
-
describe ".add_attributes" do
|
112
|
-
it "adds attributes" do
|
113
|
-
hq_object.class_eval do
|
114
|
-
add_attributes :name
|
115
|
-
with_model "Advisor", attributes: false, associations: false
|
116
|
-
end
|
117
|
-
|
118
|
-
expect(hq_object.fields.keys).to be_empty
|
119
|
-
hq_object.graphql_definition
|
120
|
-
expect(hq_object.fields.keys).to contain_exactly("name")
|
121
|
-
end
|
122
|
-
|
123
|
-
it "raises an error when adding an attribute that doesn't exist" do
|
124
|
-
hq_object.class_eval do
|
125
|
-
add_attributes :doesnt_exist
|
126
|
-
with_model "Advisor", attributes: false, associations: false
|
127
|
-
end
|
128
|
-
|
129
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "raises an error when not connected to a model" do
|
133
|
-
hq_object.class_eval do
|
134
|
-
add_attributes :name
|
135
|
-
end
|
136
|
-
|
137
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe ".add_associations" do
|
142
|
-
it "adds associations" do
|
143
|
-
hq_object.class_eval do
|
144
|
-
add_associations :organization
|
145
|
-
with_model "Advisor", attributes: false, associations: false
|
146
|
-
end
|
147
|
-
|
148
|
-
expect(hq_object.fields.keys).to be_empty
|
149
|
-
hq_object.graphql_definition
|
150
|
-
expect(hq_object.fields.keys).to contain_exactly("organization")
|
151
|
-
end
|
152
|
-
|
153
|
-
it "raises an error when adding an association that doesn't exist" do
|
154
|
-
hq_object.class_eval do
|
155
|
-
add_associations :doesnt_exist
|
156
|
-
with_model "Advisor", attributes: false, associations: false
|
157
|
-
end
|
158
|
-
|
159
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "raises an error when not connected to a model" do
|
163
|
-
hq_object.class_eval do
|
164
|
-
add_associations :organization
|
165
|
-
end
|
166
|
-
|
167
|
-
expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|