souls 0.23.5 → 0.23.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -138
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -2
- data/exe/souls +68 -68
- data/lib/souls.rb +153 -141
- data/lib/souls/gcloud/compute.rb +61 -51
- data/lib/souls/gcloud/iam.rb +22 -24
- data/lib/souls/generate/application.rb +160 -160
- data/lib/souls/generate/connection.rb +13 -15
- data/lib/souls/generate/edge.rb +13 -15
- data/lib/souls/generate/model.rb +16 -17
- data/lib/souls/generate/mutation.rb +225 -221
- data/lib/souls/generate/policy.rb +44 -45
- data/lib/souls/generate/query.rb +49 -49
- data/lib/souls/generate/resolver.rb +121 -124
- data/lib/souls/generate/rspec_factory.rb +49 -52
- data/lib/souls/generate/rspec_model.rb +17 -18
- data/lib/souls/generate/rspec_mutation.rb +193 -199
- data/lib/souls/generate/rspec_policy.rb +38 -39
- data/lib/souls/generate/rspec_query.rb +133 -140
- data/lib/souls/generate/rspec_resolver.rb +147 -154
- data/lib/souls/generate/type.rb +34 -25
- data/lib/souls/init.rb +51 -50
- data/lib/souls/version.rb +2 -1
- data/souls.gemspec +12 -7
- metadata +5 -5
@@ -1,280 +1,284 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
module
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
field :error, String, null: true
|
3
|
+
## Generate 4 Mutations - ["create", "update", "delete", "destroy_delete"]
|
4
|
+
## 1.Mutation - Create
|
5
|
+
def self.create_mutation_head(class_name: "user")
|
6
|
+
singularized_class_name = class_name.singularize.underscore
|
7
|
+
dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
|
8
|
+
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
9
|
+
file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
|
10
|
+
File.open(file_path, "w") do |new_line|
|
11
|
+
new_line.write(<<~TEXT)
|
12
|
+
module Mutations
|
13
|
+
module #{singularized_class_name.camelize}
|
14
|
+
class Create#{singularized_class_name.camelize} < BaseMutation
|
15
|
+
field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}.edge_type, null: false
|
16
|
+
field :error, String, null: true
|
18
17
|
|
19
|
-
|
20
|
-
end
|
21
|
-
file_path
|
18
|
+
TEXT
|
22
19
|
end
|
20
|
+
file_path
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def resolve **args
|
39
|
-
args[:user_id] = context[:user].id
|
40
|
-
EOS
|
41
|
-
else
|
42
|
-
new_line.write <<-EOS
|
23
|
+
def self.create_mutation_params(class_name: "souls")
|
24
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
|
25
|
+
path = "./db/schema.rb"
|
26
|
+
@on = false
|
27
|
+
@user_exist = false
|
28
|
+
@relation_params = []
|
29
|
+
File.open(file_path, "a") do |new_line|
|
30
|
+
File.open(path, "r") do |f|
|
31
|
+
f.each_line.with_index do |line, _i|
|
32
|
+
if @on
|
33
|
+
if line.include?("end") || line.include?("t.index")
|
34
|
+
if @user_exist
|
35
|
+
new_line.write(<<-TEXT)
|
43
36
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
break
|
48
|
-
end
|
49
|
-
field = "[String]" if line.include?("array: true")
|
50
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
51
|
-
field ||= type_check type
|
52
|
-
case name
|
53
|
-
when "user_id"
|
54
|
-
@user_exist = true
|
55
|
-
when /$*_id\z/
|
56
|
-
@relation_params << name
|
57
|
-
new_line.write " argument :#{name}, String, required: false\n"
|
58
|
-
when "created_at", "updated_at"
|
59
|
-
next
|
37
|
+
def resolve **args
|
38
|
+
args[:user_id] = context[:user].id
|
39
|
+
TEXT
|
60
40
|
else
|
61
|
-
new_line.write
|
41
|
+
new_line.write(<<-TEXT)
|
42
|
+
|
43
|
+
def resolve **args
|
44
|
+
TEXT
|
62
45
|
end
|
46
|
+
break
|
47
|
+
end
|
48
|
+
field = "[String]" if line.include?("array: true")
|
49
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
50
|
+
field ||= type_check(type)
|
51
|
+
case name
|
52
|
+
when "user_id"
|
53
|
+
@user_exist = true
|
54
|
+
when /$*_id\z/
|
55
|
+
@relation_params << name
|
56
|
+
new_line.write(" argument :#{name}, String, required: false\n")
|
57
|
+
when "created_at", "updated_at"
|
58
|
+
next
|
59
|
+
else
|
60
|
+
new_line.write(" argument :#{name}, #{field}, required: false\n")
|
63
61
|
end
|
64
|
-
@on = true if table_check(line: line, class_name: class_name)
|
65
62
|
end
|
63
|
+
@on = true if table_check(line: line, class_name: class_name)
|
66
64
|
end
|
67
65
|
end
|
68
|
-
@relation_params
|
69
66
|
end
|
67
|
+
@relation_params
|
68
|
+
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
def self.create_mutation_after_params(class_name: "article", relation_params: [])
|
71
|
+
return false if relation_params.empty?
|
72
|
+
|
73
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
|
74
|
+
relation_params.each do |params_name|
|
75
|
+
File.open(file_path, "a") do |new_line|
|
76
|
+
new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
|
78
77
|
end
|
79
|
-
true
|
80
78
|
end
|
79
|
+
true
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
def self.create_mutation_end(class_name: "souls")
|
83
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
|
84
|
+
File.open(file_path, "a") do |new_line|
|
85
|
+
new_line.write(<<~TEXT)
|
86
|
+
data = ::#{class_name.camelize}.new args
|
87
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
89
|
+
{ #{class_name}_edge: { node: data } }
|
90
|
+
rescue StandardError => error
|
91
|
+
GraphQL::ExecutionError.new error
|
93
92
|
end
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
97
|
-
|
98
|
-
file_path
|
95
|
+
end
|
96
|
+
TEXT
|
99
97
|
end
|
98
|
+
file_path
|
99
|
+
end
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
101
|
+
## 2.Mutation - Update
|
102
|
+
def self.update_mutation_head(class_name: "souls")
|
103
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
104
|
+
File.open(file_path, "w") do |new_line|
|
105
|
+
new_line.write(<<~TEXT)
|
106
|
+
module Mutations
|
107
|
+
module #{class_name.camelize}
|
108
|
+
class Update#{class_name.camelize} < BaseMutation
|
109
|
+
field :#{class_name}_edge, Types::#{class_name.camelize}.edge_type, null: false
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
end
|
114
|
-
file_path
|
111
|
+
argument :id, String, required: true
|
112
|
+
TEXT
|
115
113
|
end
|
114
|
+
file_path
|
115
|
+
end
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
def resolve **args
|
132
|
-
args[:user_id] = context[:user].id
|
133
|
-
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
134
|
-
EOS
|
135
|
-
else
|
136
|
-
new_line.write <<-EOS
|
117
|
+
def self.update_mutation_params(class_name: "souls")
|
118
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
119
|
+
path = "./db/schema.rb"
|
120
|
+
@on = false
|
121
|
+
@user_exist = false
|
122
|
+
@relation_params = []
|
123
|
+
File.open(file_path, "a") do |new_line|
|
124
|
+
File.open(path, "r") do |f|
|
125
|
+
f.each_line.with_index do |line, _i|
|
126
|
+
if @on
|
127
|
+
if line.include?("end") || line.include?("t.index")
|
128
|
+
if @user_exist
|
129
|
+
new_line.write(<<-TEXT)
|
137
130
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
break
|
143
|
-
end
|
144
|
-
field = "[String]" if line.include?("array: true")
|
145
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
146
|
-
field ||= type_check type
|
147
|
-
case name
|
148
|
-
when "user_id"
|
149
|
-
@user_exist = true
|
150
|
-
when /$*_id\z/
|
151
|
-
@relation_params << name
|
152
|
-
new_line.write " argument :#{name}, String, required: false\n"
|
153
|
-
when "created_at", "updated_at"
|
154
|
-
next
|
131
|
+
def resolve **args
|
132
|
+
args[:user_id] = context[:user].id
|
133
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
134
|
+
TEXT
|
155
135
|
else
|
156
|
-
new_line.write
|
136
|
+
new_line.write(<<-TEXT)
|
137
|
+
|
138
|
+
def resolve **args
|
139
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
140
|
+
TEXT
|
157
141
|
end
|
142
|
+
break
|
143
|
+
end
|
144
|
+
field = "[String]" if line.include?("array: true")
|
145
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
146
|
+
field ||= type_check(type)
|
147
|
+
case name
|
148
|
+
when "user_id"
|
149
|
+
@user_exist = true
|
150
|
+
when /$*_id\z/
|
151
|
+
@relation_params << name
|
152
|
+
new_line.write(" argument :#{name}, String, required: false\n")
|
153
|
+
when "created_at", "updated_at"
|
154
|
+
next
|
155
|
+
else
|
156
|
+
new_line.write(" argument :#{name}, #{field}, required: false\n")
|
158
157
|
end
|
159
|
-
@on = true if table_check(line: line, class_name: class_name)
|
160
158
|
end
|
159
|
+
@on = true if table_check(line: line, class_name: class_name)
|
161
160
|
end
|
162
161
|
end
|
163
|
-
@relation_params
|
164
162
|
end
|
163
|
+
@relation_params
|
164
|
+
end
|
165
165
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
166
|
+
def self.update_mutation_after_params(class_name: "article", relation_params: [])
|
167
|
+
return false if relation_params.empty?
|
168
|
+
|
169
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
170
|
+
relation_params.each do |params_name|
|
171
|
+
File.open(file_path, "a") do |new_line|
|
172
|
+
new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
|
173
173
|
end
|
174
|
-
true
|
175
174
|
end
|
175
|
+
true
|
176
|
+
end
|
176
177
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
178
|
+
def self.update_mutation_end(class_name: "souls")
|
179
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
180
|
+
File.open(file_path, "a") do |new_line|
|
181
|
+
new_line.write(<<~TEXT)
|
182
|
+
#{class_name} = ::#{class_name.camelize}.find args[:id]
|
183
|
+
#{class_name}.update args
|
184
|
+
{ #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
|
185
|
+
rescue StandardError => error
|
186
|
+
GraphQL::ExecutionError.new error
|
187
187
|
end
|
188
188
|
end
|
189
189
|
end
|
190
|
-
|
191
|
-
|
192
|
-
file_path
|
190
|
+
end
|
191
|
+
TEXT
|
193
192
|
end
|
193
|
+
file_path
|
194
|
+
end
|
194
195
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
196
|
+
def self.update_mutation(class_name: "souls")
|
197
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
198
|
+
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
199
|
+
|
200
|
+
update_mutation_head(class_name: class_name)
|
201
|
+
relation_params = update_mutation_params(class_name: class_name)
|
202
|
+
update_mutation_after_params(class_name: class_name, relation_params: relation_params)
|
203
|
+
update_mutation_end(class_name: class_name)
|
204
|
+
end
|
205
|
+
|
206
|
+
# 3. Mutation - Delete
|
207
|
+
def self.delete_mutation(class_name: "souls")
|
208
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
|
209
|
+
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
203
210
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
module #{class_name.camelize}
|
212
|
-
class Delete#{class_name.camelize} < BaseMutation
|
213
|
-
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
214
|
-
argument :id, String, required: true
|
211
|
+
File.open(file_path, "w") do |f|
|
212
|
+
f.write(<<~TEXT)
|
213
|
+
module Mutations
|
214
|
+
module #{class_name.camelize}
|
215
|
+
class Delete#{class_name.camelize} < BaseMutation
|
216
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
217
|
+
argument :id, String, required: true
|
215
218
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
end
|
219
|
+
def resolve **args
|
220
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
221
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
222
|
+
#{class_name}.update(is_deleted: true)
|
223
|
+
{ #{class_name}: ::#{class_name.camelize}.find(data_id) }
|
224
|
+
rescue StandardError => error
|
225
|
+
GraphQL::ExecutionError.new error
|
224
226
|
end
|
225
227
|
end
|
226
228
|
end
|
227
|
-
|
228
|
-
|
229
|
-
file_path
|
229
|
+
end
|
230
|
+
TEXT
|
230
231
|
end
|
232
|
+
file_path
|
233
|
+
end
|
234
|
+
|
235
|
+
# 4. Mutation - Destroy Delete
|
236
|
+
def self.destroy_delete_mutation(class_name: "souls")
|
237
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/destroy_delete_#{class_name}.rb"
|
238
|
+
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
231
239
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
module #{class_name.camelize}
|
240
|
-
class DestroyDelete#{class_name.camelize} < BaseMutation
|
241
|
-
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
242
|
-
argument :id, String, required: true
|
240
|
+
File.open(file_path, "w") do |f|
|
241
|
+
f.write(<<~TEXT)
|
242
|
+
module Mutations
|
243
|
+
module #{class_name.camelize}
|
244
|
+
class DestroyDelete#{class_name.camelize} < BaseMutation
|
245
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
246
|
+
argument :id, String, required: true
|
243
247
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
end
|
248
|
+
def resolve **args
|
249
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
250
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
251
|
+
#{class_name}.destroy
|
252
|
+
{ #{class_name}: #{class_name} }
|
253
|
+
rescue StandardError => error
|
254
|
+
GraphQL::ExecutionError.new error
|
252
255
|
end
|
253
256
|
end
|
254
257
|
end
|
255
|
-
|
256
|
-
|
257
|
-
file_path
|
258
|
-
rescue StandardError => error
|
259
|
-
puts error
|
258
|
+
end
|
259
|
+
TEXT
|
260
260
|
end
|
261
|
+
file_path
|
262
|
+
rescue StandardError => e
|
263
|
+
puts(e)
|
264
|
+
end
|
261
265
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
266
|
+
def self.mutation(class_name: "souls")
|
267
|
+
singularized_class_name = class_name.singularize
|
268
|
+
file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
|
269
|
+
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
270
|
+
|
271
|
+
create_mutation_head(class_name: singularized_class_name)
|
272
|
+
relation_params = create_mutation_params(class_name: singularized_class_name)
|
273
|
+
create_mutation_after_params(class_name: singularized_class_name, relation_params: relation_params)
|
274
|
+
create_mutation_end(class_name: singularized_class_name)
|
275
|
+
update_mutation(class_name: singularized_class_name)
|
276
|
+
delete_mutation(class_name: singularized_class_name)
|
277
|
+
destroy_delete_mutation(class_name: singularized_class_name)
|
278
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
279
|
+
file_path
|
280
|
+
rescue StandardError => e
|
281
|
+
raise(StandardError, e)
|
278
282
|
end
|
279
283
|
end
|
280
284
|
end
|