hq-graphql 0.0.2 → 1.0.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/README.md +93 -7
- data/lib/hq/graphql/active_record_extensions.rb +125 -0
- data/lib/hq/graphql/input_extensions.rb +56 -0
- data/lib/hq/graphql/input_object.rb +17 -0
- data/lib/hq/graphql/inputs.rb +32 -0
- data/lib/hq/graphql/mutation.rb +13 -0
- data/lib/hq/graphql/object.rb +11 -77
- data/lib/hq/graphql/resource/mutation.rb +32 -0
- data/lib/hq/graphql/resource.rb +199 -0
- data/lib/hq/graphql/root_mutation.rb +20 -0
- data/lib/hq/graphql/root_query.rb +29 -0
- data/lib/hq/graphql/scalars.rb +9 -0
- data/lib/hq/graphql/types/uuid.rb +3 -3
- data/lib/hq/graphql/types.rb +14 -22
- data/lib/hq/graphql/version.rb +1 -1
- data/lib/hq/graphql.rb +27 -11
- data/spec/internal/db/schema.rb +2 -2
- data/spec/lib/graphql/active_record_extensions_spec.rb +63 -0
- data/spec/lib/graphql/inputs_spec.rb +40 -0
- data/spec/lib/graphql/mutation_spec.rb +173 -0
- data/spec/lib/graphql/object_spec.rb +173 -0
- data/spec/lib/graphql/resource_spec.rb +374 -0
- data/spec/lib/graphql/types/uuid_spec.rb +65 -0
- data/spec/lib/graphql/types_spec.rb +40 -0
- data/spec/rails_helper.rb +2 -0
- metadata +28 -14
- data/spec/internal/app/graphql/query.rb +0 -18
- data/spec/internal/app/graphql/schema.rb +0 -3
- data/spec/internal/app/graphql/user_type.rb +0 -3
- data/spec/lib/object_spec.rb +0 -198
- data/spec/lib/types_spec.rb +0 -60
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe ::HQ::GraphQL::Mutation 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.payload_type
|
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.payload_type
|
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.payload_type }.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.payload_type }.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.payload_type
|
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.payload_type }.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.payload_type }.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.payload_type
|
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.payload_type
|
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.payload_type
|
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.payload_type }.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.payload_type }.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.payload_type
|
150
|
+
expect(hq_input_object.arguments.keys).to contain_exactly("organizationAttributes")
|
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.payload_type }.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.payload_type }.to raise_error(described_class::Error)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
@@ -0,0 +1,173 @@
|
|
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
|