souls 0.17.9 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,189 @@
1
+ module Souls
2
+ module Generate
3
+ class << self
4
+ ## Generate Rspec Resolver
5
+ def rspec_resolver_head class_name: "souls"
6
+ file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
7
+ File.open(file_path, "w") do |f|
8
+ f.write <<~EOS
9
+ RSpec.describe \"#{class_name.camelize}Search Resolver テスト\" do
10
+ describe "削除フラグ false の #{class_name.camelize} を返却する" do
11
+ EOS
12
+ end
13
+ end
14
+
15
+ def rspec_resolver_after_head class_name: "souls"
16
+ file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
17
+ path = "./db/schema.rb"
18
+ @on = false
19
+ @user_exist = false
20
+ @relation_params = []
21
+ File.open(file_path, "a") do |new_line|
22
+ File.open(path, "r") do |f|
23
+ f.each_line.with_index do |line, i|
24
+ if @on
25
+ if line.include?("end") || line.include?("t.index")
26
+ if @relation_params.empty?
27
+ new_line.write <<-EOS
28
+ let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
29
+
30
+ let(:query) do
31
+ %(query {
32
+ #{class_name.singularize.camelize(:lower)}Search(filter: {
33
+ isDeleted: false
34
+ }) {
35
+ edges {
36
+ cursor
37
+ node {
38
+ id
39
+ EOS
40
+ else
41
+ new_line.write <<-EOS
42
+ let!(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(", ")}) }
43
+
44
+ let(:query) do
45
+ %(query {
46
+ #{class_name.singularize.camelize(:lower)}Search(filter: {
47
+ isDeleted: false
48
+ }) {
49
+ edges {
50
+ cursor
51
+ node {
52
+ id
53
+ EOS
54
+ end
55
+ break
56
+ end
57
+ _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
58
+ case name
59
+ when /$*_id\z/
60
+ relation_col = name.gsub("_id", "")
61
+ @relation_params << "#{name}: #{relation_col}.id"
62
+ new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
63
+ end
64
+ end
65
+ if table_check(line: line, class_name: class_name)
66
+ @on = true
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def rspec_resolver_params class_name: "souls"
74
+ file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
75
+ path = "./db/schema.rb"
76
+ @on = false
77
+ File.open(file_path, "a") do |new_line|
78
+ File.open(path, "r") do |f|
79
+ f.each_line.with_index do |line, i|
80
+ if @on
81
+ if line.include?("end") || line.include?("t.index")
82
+ new_line.write <<-EOS
83
+ }
84
+ }
85
+ nodes {
86
+ id
87
+ }
88
+ pageInfo {
89
+ endCursor
90
+ hasNextPage
91
+ startCursor
92
+ hasPreviousPage
93
+ }
94
+ }
95
+ }
96
+ )
97
+ end
98
+
99
+ subject(:result) do
100
+ SoulsApiSchema.execute(query).as_json
101
+ end
102
+
103
+ it "return #{class_name.camelize} Data" do
104
+ begin
105
+ a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}Search", "edges")[0]["node"]
106
+ raise unless a1.present?
107
+ rescue
108
+ raise StandardError, result
109
+ end
110
+ expect(a1).to include(
111
+ "id" => be_a(String),
112
+ EOS
113
+ break
114
+ end
115
+ _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
116
+ case name
117
+ when "user_id", "created_at", "updated_at", /$*_id\z/
118
+ next
119
+ else
120
+ new_line.write " #{name.camelize(:lower)}\n"
121
+ end
122
+ end
123
+ if table_check(line: line, class_name: class_name)
124
+ @on = true
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ def rspec_resolver_end class_name: "souls"
132
+ file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
133
+ path = "./db/schema.rb"
134
+ @on = false
135
+ File.open(file_path, "a") do |new_line|
136
+ File.open(path, "r") do |f|
137
+ f.each_line.with_index do |line, i|
138
+ if @on
139
+ if line.include?("end") || line.include?("t.index")
140
+ new_line.write <<~EOS
141
+ )
142
+ end
143
+ end
144
+ end
145
+ EOS
146
+ break
147
+ end
148
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
149
+ field ||= type_check type
150
+ array_true = line.include?("array: true")
151
+ case name
152
+ when "user_id", "created_at", "updated_at", /$*_id\z/
153
+ next
154
+ else
155
+ case type
156
+ when "text", "date", "datetime"
157
+ if array_true
158
+ new_line.write " \"#{name.camelize(:lower)}\" => be_all(String),\n"
159
+ else
160
+ new_line.write " \"#{name.camelize(:lower)}\" => be_a(String),\n"
161
+ end
162
+ when "boolean"
163
+ new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
164
+ when "string", "bigint", "integer", "float"
165
+ new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
166
+ end
167
+ end
168
+ end
169
+ if table_check(line: line, class_name: class_name)
170
+ @on = true
171
+ end
172
+ end
173
+ end
174
+ end
175
+ file_path
176
+ end
177
+
178
+ def rspec_resolver class_name: "souls"
179
+ singularized_class_name = class_name.singularize
180
+ file_path = "#{Dir.pwd}/spec/resolvers/#{singularized_class_name}_search_spec.rb"
181
+ return "Resolver already exist! #{file_path}" if File.exist? file_path
182
+ rspec_resolver_head class_name: singularized_class_name
183
+ rspec_resolver_after_head class_name: singularized_class_name
184
+ rspec_resolver_params class_name: singularized_class_name
185
+ rspec_resolver_end class_name: singularized_class_name
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,83 @@
1
+ module Souls
2
+ module Generate
3
+ class << self
4
+ ## Generate 2 Types
5
+ ## 1. Type
6
+ ## 2. Node Type
7
+ def create_type_head class_name: "souls"
8
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
9
+ File.open(file_path, "w") do |f|
10
+ f.write <<~EOS
11
+ module Types
12
+ class #{class_name.camelize}Type < BaseObject
13
+ implements GraphQL::Types::Relay::Node
14
+
15
+ EOS
16
+ end
17
+ end
18
+
19
+ def create_type_params class_name: "souls"
20
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
21
+ path = "./db/schema.rb"
22
+ @on = false
23
+ File.open(file_path, "a") do |new_line|
24
+ File.open(path, "r") do |f|
25
+ f.each_line.with_index do |line, i|
26
+ if @on
27
+ new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
28
+ field = "[String]" if line.include?("array: true")
29
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
30
+ field ||= type_check type
31
+ case name
32
+ when /$*_id\z/
33
+ new_line.write " field :#{name.gsub("_id", "")}, Types::#{name.gsub("_id", "").singularize.camelize}Type, null: false\n"
34
+ else
35
+ new_line.write " field :#{name}, #{field}, null: true\n"
36
+ end
37
+ end
38
+ if table_check(line: line, class_name: class_name)
39
+ @on = true
40
+ new_line.write " global_id_field :id\n"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def create_type_end class_name: "souls"
48
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
49
+ File.open(file_path, "a") do |f|
50
+ f.write <<~EOS
51
+ end
52
+ end
53
+ EOS
54
+ end
55
+ file_path
56
+ end
57
+
58
+ def node_type class_name: "souls"
59
+ file_path = "./app/graphql/types/#{class_name.singularize}_node_type.rb"
60
+ File.open(file_path, "w") do |f|
61
+ f.write <<~EOS
62
+ module Types
63
+ class #{class_name.camelize}NodeType < BaseObject
64
+ field :node, Types::#{class_name.camelize}Type, null: true
65
+ end
66
+ end
67
+ EOS
68
+ end
69
+ file_path
70
+ end
71
+
72
+ def type class_name: "souls"
73
+ singularized_class_name = class_name.singularize
74
+ create_type_head class_name: singularized_class_name
75
+ create_type_params class_name: singularized_class_name
76
+ [
77
+ create_type_end(class_name: singularized_class_name),
78
+ node_type(class_name: singularized_class_name)
79
+ ]
80
+ end
81
+ end
82
+ end
83
+ end
data/lib/souls/init.rb CHANGED
@@ -1,20 +1,35 @@
1
1
  module Souls
2
2
  module Init
3
3
  class << self
4
- def get_version repository_name: "souls_service"
4
+ def get_version repository_name: "souls_api"
5
5
  data = JSON.parse `curl \
6
6
  -H "Accept: application/vnd.github.v3+json" \
7
7
  -s https://api.github.com/repos/elsoul/#{repository_name}/releases`
8
8
  data[0]["tag_name"]
9
9
  end
10
10
 
11
- def download_souls app_name: "souls", repository_name: "souls_service"
11
+ def initial_config_init app_name: "souls", strain: "api"
12
+ FileUtils.touch "./#{app_name}/config/souls.rb"
13
+ file_path = "./#{app_name}/config/souls.rb"
14
+ File.open(file_path, "w") do |f|
15
+ f.write <<~EOS
16
+ Souls.configure do |config|
17
+ config.app = "#{app_name}"
18
+ config.strain = "#{strain}"
19
+ end
20
+ EOS
21
+ end
22
+ rescue StandardError => error
23
+ puts error
24
+ end
25
+
26
+ def download_souls app_name: "souls", repository_name: "souls_api "
12
27
  version = get_version repository_name: repository_name
13
28
  system "curl -OL https://github.com/elsoul/#{repository_name}/archive/#{version}.tar.gz"
14
29
  system "tar -zxvf ./#{version}.tar.gz"
15
30
  system "mkdir #{app_name}"
16
31
  folder = version.delete "v"
17
- system "cp -r #{repository_name}-#{folder}/* #{app_name}/"
32
+ system "cp -r #{repository_name}-#{folder}/. #{app_name}/"
18
33
  system "rm -rf #{version}.tar.gz && rm -rf #{repository_name}-#{folder}"
19
34
  txt = <<~TEXT
20
35
  _____ ____ __ ____#{' '}
@@ -31,1137 +46,6 @@ module Souls
31
46
  puts "$ cd #{app_name}"
32
47
  puts "------------------------------"
33
48
  end
34
-
35
- def model class_name: "souls"
36
- file_path = "./app/models/#{class_name.singularize}.rb"
37
- return ["Model already exist! #{file_path}"] if File.exist? file_path
38
- File.open(file_path, "w") do |f|
39
- f.write <<~EOS
40
- class #{class_name.camelize} < ActiveRecord::Base
41
- end
42
- EOS
43
- end
44
- [file_path]
45
- end
46
-
47
- def test_dir
48
- FileUtils.mkdir_p "./app/graphql/mutations"
49
- FileUtils.mkdir_p "./app/graphql/queries"
50
- FileUtils.mkdir_p "./app/graphql/types"
51
- FileUtils.mkdir_p "./app/graphql/resolvers"
52
- FileUtils.mkdir_p "./app/jobs"
53
- FileUtils.mkdir_p "./app/models"
54
- FileUtils.mkdir_p "./spec/factories"
55
- FileUtils.mkdir_p "./spec/queries"
56
- FileUtils.mkdir_p "./spec/mutations"
57
- FileUtils.mkdir_p "./spec/models"
58
- FileUtils.mkdir_p "./db/"
59
- FileUtils.touch "./db/schema.rb"
60
- puts "test dir created!"
61
- end
62
-
63
- def type_check type
64
- {
65
- bigint: "Integer",
66
- string: "String",
67
- float: "Float",
68
- text: "String",
69
- datetime: "GraphQL::Types::ISO8601DateTime",
70
- date: "GraphQL::Types::ISO8601DateTime",
71
- boolean: "Boolean",
72
- integer: "Integer"
73
- }[type.to_sym]
74
- end
75
-
76
- def get_test_type type
77
- {
78
- bigint: 1,
79
- float: 4.2,
80
- string: '"MyString"',
81
- text: '"MyString"',
82
- datetime: "Time.now",
83
- date: "Time.now",
84
- boolean: false,
85
- integer: 1
86
- }[type.to_sym]
87
- end
88
-
89
- def table_check line: "", class_name: ""
90
- if line.include?("create_table") && (line.split(" ")[1].gsub("\"", "").gsub(",", "") == class_name.pluralize.to_s)
91
- return true
92
- end
93
- false
94
- end
95
-
96
- def create_mutation_head class_name: "souls"
97
- dir_name = "./app/graphql/mutations/#{class_name}"
98
- FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
99
- file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
100
- File.open(file_path, "w") do |new_line|
101
- new_line.write <<~EOS
102
- module Mutations
103
- module #{class_name.camelize}
104
- class Create#{class_name.camelize} < BaseMutation
105
- field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
106
- field :error, String, null: true
107
-
108
- EOS
109
- end
110
- end
111
-
112
- def create_mutation_params class_name: "souls"
113
- file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
114
- path = "./db/schema.rb"
115
- @on = false
116
- @user_exist = false
117
- @relation_params = []
118
- File.open(file_path, "a") do |new_line|
119
- File.open(path, "r") do |f|
120
- f.each_line.with_index do |line, i|
121
- if @on
122
- if line.include?("end") || line.include?("t.index")
123
- if @user_exist
124
- new_line.write <<-EOS
125
-
126
- def resolve **args
127
- args[:user_id] = context[:user].id
128
- EOS
129
- else
130
- new_line.write <<-EOS
131
-
132
- def resolve **args
133
- EOS
134
- end
135
- break
136
- end
137
- field = "[String]" if line.include?("array: true")
138
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
139
- field ||= type_check type
140
- case name
141
- when "user_id"
142
- @user_exist = true
143
- when /$*_id\z/
144
- @relation_params << name
145
- new_line.write " argument :#{name}, String, required: false\n"
146
- when "created_at", "updated_at"
147
- next
148
- else
149
- new_line.write " argument :#{name}, #{field}, required: false\n"
150
- end
151
- end
152
- @on = true if table_check(line: line, class_name: class_name)
153
- end
154
- end
155
- end
156
- @relation_params
157
- end
158
-
159
- def create_mutation_after_params class_name: "article", relation_params: []
160
- return false if relation_params.empty?
161
- file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
162
- relation_params.each do |params_name|
163
- File.open(file_path, "a") do |new_line|
164
- new_line.write " _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n"
165
- end
166
- end
167
- true
168
- end
169
-
170
- def create_mutation_end class_name: "souls"
171
- file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
172
- File.open(file_path, "a") do |new_line|
173
- new_line.write <<~EOS
174
- #{class_name} = ::#{class_name.camelize}.new args
175
- if #{class_name}.save
176
- { #{class_name}_edge: { node: #{class_name} } }
177
- else
178
- { error: #{class_name}.errors.full_messages }
179
- end
180
- rescue StandardError => error
181
- GraphQL::ExecutionError.new error
182
- end
183
- end
184
- end
185
- end
186
- EOS
187
- end
188
- file_path
189
- end
190
-
191
- def update_mutation_head class_name: "souls"
192
- file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
193
- File.open(file_path, "w") do |new_line|
194
- new_line.write <<~EOS
195
- module Mutations
196
- module #{class_name.camelize}
197
- class Update#{class_name.camelize} < BaseMutation
198
- field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
199
-
200
- argument :id, String, required: true
201
- EOS
202
- end
203
- end
204
-
205
- def update_mutation_params class_name: "souls"
206
- file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
207
- path = "./db/schema.rb"
208
- @on = false
209
- @user_exist = false
210
- @relation_params = []
211
- File.open(file_path, "a") do |new_line|
212
- File.open(path, "r") do |f|
213
- f.each_line.with_index do |line, i|
214
- if @on
215
- if line.include?("end") || line.include?("t.index")
216
- if @user_exist
217
- new_line.write <<-EOS
218
-
219
- def resolve **args
220
- args[:user_id] = context[:user].id
221
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
222
- EOS
223
- else
224
- new_line.write <<-EOS
225
-
226
- def resolve **args
227
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
228
- EOS
229
- end
230
- break
231
- end
232
- field = "[String]" if line.include?("array: true")
233
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
234
- field ||= type_check type
235
- case name
236
- when "user_id"
237
- @user_exist = true
238
- when /$*_id\z/
239
- @relation_params << name
240
- new_line.write " argument :#{name}, String, required: false\n"
241
- when "created_at", "updated_at"
242
- next
243
- else
244
- new_line.write " argument :#{name}, #{field}, required: false\n"
245
- end
246
- end
247
- @on = true if table_check(line: line, class_name: class_name)
248
- end
249
- end
250
- end
251
- @relation_params
252
- end
253
-
254
- def update_mutation_after_params class_name: "article", relation_params: []
255
- return false if relation_params.empty?
256
- file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
257
- relation_params.each do |params_name|
258
- File.open(file_path, "a") do |new_line|
259
- new_line.write " _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n"
260
- end
261
- end
262
- true
263
- end
264
-
265
- def update_mutation_end class_name: "souls"
266
- file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
267
- File.open(file_path, "a") do |new_line|
268
- new_line.write <<~EOS
269
- #{class_name} = ::#{class_name.camelize}.find args[:id]
270
- #{class_name}.update args
271
- { #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
272
- rescue StandardError => error
273
- GraphQL::ExecutionError.new error
274
- end
275
- end
276
- end
277
- end
278
- EOS
279
- end
280
- file_path
281
- end
282
-
283
- def update_mutation class_name: "souls"
284
- update_mutation_head class_name: class_name
285
- relation_params = update_mutation_params class_name: class_name
286
- update_mutation_after_params class_name: class_name, relation_params: relation_params
287
- update_mutation_end class_name: class_name
288
- end
289
-
290
- def delete_mutation class_name: "souls"
291
- file_path = "./app/graphql/mutations/#{class_name}/delete_#{class_name}.rb"
292
- File.open(file_path, "w") do |f|
293
- f.write <<~EOS
294
- module Mutations
295
- module #{class_name.camelize}
296
- class Delete#{class_name.camelize} < BaseMutation
297
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
298
- argument :id, String, required: true
299
-
300
- def resolve **args
301
- _, data_id = SoulsApiSchema.from_global_id args[:id]
302
- #{class_name} = ::#{class_name.camelize}.find data_id
303
- #{class_name}.update(is_deleted: true)
304
- { #{class_name}: ::#{class_name.camelize}.find(data_id) }
305
- rescue StandardError => error
306
- GraphQL::ExecutionError.new error
307
- end
308
- end
309
- end
310
- end
311
- EOS
312
- end
313
- file_path
314
- end
315
-
316
- def destroy_delete_mutation class_name: "souls"
317
- file_path = "./app/graphql/mutations/#{class_name}/destroy_delete_#{class_name}.rb"
318
- File.open(file_path, "w") do |f|
319
- f.write <<~EOS
320
- module Mutations
321
- module #{class_name.camelize}
322
- class DestroyDelete#{class_name.camelize} < BaseMutation
323
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
324
- argument :id, String, required: true
325
-
326
- def resolve **args
327
- _, data_id = SoulsApiSchema.from_global_id args[:id]
328
- #{class_name} = ::#{class_name.camelize}.find data_id
329
- #{class_name}.destroy
330
- { #{class_name}: #{class_name} }
331
- rescue StandardError => error
332
- GraphQL::ExecutionError.new error
333
- end
334
- end
335
- end
336
- end
337
- EOS
338
- end
339
- file_path
340
- end
341
-
342
- def create_confirm dir_path: ""
343
- puts "Directory already exists, Overwrite?? (Y/N)\n#{dir_path}"
344
- input = STDIN.gets.chomp
345
- return true if input == "Y"
346
- raise StandardError.new "Directory Already Exist!\n#{dir_path}"
347
- end
348
-
349
- def mutation class_name: "souls"
350
- singularized_class_name = class_name.singularize
351
-
352
- create_mutation_head class_name: singularized_class_name
353
- relation_params = create_mutation_params class_name: singularized_class_name
354
- create_mutation_after_params class_name: singularized_class_name, relation_params: relation_params
355
- [
356
- create_mutation_end(class_name: singularized_class_name),
357
- update_mutation(class_name: singularized_class_name),
358
- delete_mutation(class_name: singularized_class_name),
359
- destroy_delete_mutation(class_name: singularized_class_name)
360
- ]
361
- end
362
-
363
- def create_queries class_name: "souls"
364
- file_path = "./app/graphql/queries/#{class_name.pluralize}.rb"
365
- File.open(file_path, "w") do |f|
366
- f.write <<~EOS
367
- module Queries
368
- class #{class_name.camelize.pluralize} < Queries::BaseQuery
369
- type [Types::#{class_name.camelize}Type], null: false
370
-
371
- def resolve
372
- ::#{class_name.camelize}.all
373
- rescue StandardError => error
374
- GraphQL::ExecutionError.new error
375
- end
376
- end
377
- end
378
- EOS
379
- end
380
- file_path
381
- end
382
-
383
- def create_query class_name: "souls"
384
- file_path = "./app/graphql/queries/#{class_name}.rb"
385
- File.open(file_path, "w") do |f|
386
- f.write <<~EOS
387
- module Queries
388
- class #{class_name.camelize} < Queries::BaseQuery
389
- type Types::#{class_name.camelize}Type, null: false
390
- argument :id, String, required: true
391
-
392
- def resolve **args
393
- _, data_id = SoulsApiSchema.from_global_id args[:id]
394
- ::#{class_name.camelize}.find(data_id)
395
- rescue StandardError => error
396
- GraphQL::ExecutionError.new error
397
- end
398
- end
399
- end
400
- EOS
401
- file_path
402
- end
403
- end
404
-
405
- def query class_name: "souls"
406
- singularized_class_name = class_name.singularize
407
- [create_query(class_name: singularized_class_name), create_queries(class_name: singularized_class_name)]
408
- end
409
-
410
- def create_type_head class_name: "souls"
411
- file_path = "./app/graphql/types/#{class_name}_type.rb"
412
- File.open(file_path, "w") do |f|
413
- f.write <<~EOS
414
- module Types
415
- class #{class_name.camelize}Type < GraphQL::Schema::Object
416
- implements GraphQL::Types::Relay::Node
417
-
418
- EOS
419
- end
420
- end
421
-
422
- def create_type_params class_name: "souls"
423
- file_path = "./app/graphql/types/#{class_name}_type.rb"
424
- path = "./db/schema.rb"
425
- @on = false
426
- File.open(file_path, "a") do |new_line|
427
- File.open(path, "r") do |f|
428
- f.each_line.with_index do |line, i|
429
- if @on
430
- new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
431
- field = "[String]" if line.include?("array: true")
432
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
433
- field ||= type_check type
434
- case name
435
- when /$*_id\z/
436
- new_line.write " field :#{name.gsub("_id", "")}, Types::#{name.gsub("_id", "").singularize.camelize}Type, null: false\n"
437
- else
438
- new_line.write " field :#{name}, #{field}, null: true\n"
439
- end
440
- end
441
- if table_check(line: line, class_name: class_name)
442
- @on = true
443
- new_line.write " global_id_field :id\n"
444
- end
445
- end
446
- end
447
- end
448
- end
449
-
450
- def create_type_end class_name: "souls"
451
- file_path = "./app/graphql/types/#{class_name}_type.rb"
452
- File.open(file_path, "a") do |f|
453
- f.write <<~EOS
454
- end
455
- end
456
- EOS
457
- end
458
- [file_path]
459
- end
460
-
461
- def type class_name: "souls"
462
- singularized_class_name = class_name.singularize
463
- create_type_head class_name: singularized_class_name
464
- create_type_params class_name: singularized_class_name
465
- create_type_end class_name: singularized_class_name
466
- end
467
-
468
- def rspec_factory_head class_name: "souls"
469
- file_path = "./spec/factories/#{class_name.pluralize}.rb"
470
- File.open(file_path, "w") do |f|
471
- f.write <<~EOS
472
- FactoryBot.define do
473
- factory :#{class_name} do
474
- EOS
475
- end
476
- end
477
-
478
- def rspec_factory_params class_name: "souls"
479
- file_path = "./spec/factories/#{class_name.pluralize}.rb"
480
- path = "./db/schema.rb"
481
- @on = false
482
- File.open(file_path, "a") do |new_line|
483
- File.open(path, "r") do |f|
484
- f.each_line.with_index do |line, i|
485
- if @on
486
- new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
487
- field = '["tag1", "tag2", "tag3"]' if line.include?("array: true")
488
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
489
- field ||= get_test_type type
490
- if type == "bigint" && name.include?("_id")
491
- id_name = name.gsub("_id", "")
492
- new_line.write " association :#{id_name}, factory: :#{id_name}\n"
493
- else
494
- new_line.write " #{name} { #{field} }\n"
495
- end
496
- end
497
- if table_check(line: line, class_name: class_name)
498
- @on = true
499
- end
500
- end
501
- end
502
- end
503
- end
504
-
505
- def rspec_factory_end class_name: "souls"
506
- file_path = "./spec/factories/#{class_name.pluralize}.rb"
507
- File.open(file_path, "a") do |f|
508
- f.write <<~EOS
509
- end
510
- end
511
- EOS
512
- end
513
- [file_path]
514
- end
515
-
516
- def rspec_factory class_name: "souls"
517
- file_path = "./spec/factories/#{class_name.pluralize}.rb"
518
- return ["Factory aleady exist! #{file_path}"] if File.exist? file_path
519
- singularized_class_name = class_name.singularize
520
- rspec_factory_head class_name: singularized_class_name
521
- rspec_factory_params class_name: singularized_class_name
522
- rspec_factory_end class_name: singularized_class_name
523
- end
524
-
525
- def rspec_model class_name: "souls"
526
- file_path = "./spec/models/#{class_name}_spec.rb"
527
- return ["Aleady Exist!"] if File.exist? file_path
528
- File.open(file_path, "w") do |f|
529
- f.write <<~EOS
530
- RSpec.describe "#{class_name.camelize} Model テスト", type: :model do
531
- describe "#{class_name.camelize} データを書き込む" do
532
- it "valid #{class_name.camelize} Model" do
533
- expect(FactoryBot.build(:#{class_name.singularize})).to be_valid
534
- end
535
- end
536
- end
537
- EOS
538
- end
539
- [file_path]
540
- end
541
-
542
- def rspec_mutation_head class_name: "souls"
543
- file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
544
- File.open(file_path, "w") do |f|
545
- f.write <<~EOS
546
- RSpec.describe \"#{class_name.camelize} Mutation テスト\" do
547
- describe "#{class_name.camelize} データを登録する" do
548
- EOS
549
- end
550
- end
551
-
552
- def rspec_mutation_after_head class_name: "souls"
553
- file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
554
- path = "./db/schema.rb"
555
- @on = false
556
- @user_exist = false
557
- @relation_params = []
558
- File.open(file_path, "a") do |new_line|
559
- File.open(path, "r") do |f|
560
- f.each_line.with_index do |line, i|
561
- if @on
562
- if line.include?("end") || line.include?("t.index")
563
- if @relation_params.empty?
564
- new_line.write <<-EOS
565
- let(:#{class_name}) { FactoryBot.attributes_for(:#{class_name}) }
566
-
567
- let(:mutation) do
568
- %(mutation {
569
- create#{class_name.camelize}(input: {
570
- EOS
571
- else
572
- new_line.write <<-EOS
573
- let(:#{class_name}) { FactoryBot.attributes_for(:#{class_name}, #{@relation_params.join(", ")}) }
574
-
575
- let(:mutation) do
576
- %(mutation {
577
- create#{class_name.camelize}(input: {
578
- EOS
579
- end
580
- break
581
- end
582
- _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
583
- case name
584
- when "user_id"
585
- relation_col = name.gsub("_id", "")
586
- new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
587
- when /$*_id\z/
588
- relation_col = name.gsub("_id", "")
589
- @relation_params << "#{name}: get_global_key(\"#{name.singularize.camelize.gsub("Id", "")}\", #{relation_col}.id)"
590
- new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
591
- end
592
- end
593
- if table_check(line: line, class_name: class_name)
594
- @on = true
595
- end
596
- end
597
- end
598
- end
599
- end
600
-
601
- def rspec_mutation_params class_name: "souls"
602
- file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
603
- path = "./db/schema.rb"
604
- @on = false
605
- @user_exist = false
606
- File.open(file_path, "a") do |new_line|
607
- File.open(path, "r") do |f|
608
- f.each_line.with_index do |line, i|
609
- if @on
610
- if line.include?("end") || line.include?("t.index")
611
- new_line.write " }) {\n #{class_name.singularize.camelize(:lower)}Edge {\n node {\n"
612
- new_line.write " id\n"
613
- break
614
- end
615
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
616
- array_true = line.include?("array: true")
617
- case name
618
- when "created_at", "updated_at"
619
- next
620
- when "user_id"
621
- @user_exist = true
622
- when /$*_id\z/
623
- new_line.write " #{name.singularize.camelize(:lower)}: \"\#{#{class_name.singularize}[:#{name.singularize.underscore}]}\"\n"
624
- else
625
- case type
626
- when "string", "text", "date", "datetime"
627
- if array_true
628
- new_line.write " #{name.pluralize.camelize(:lower)}: \#{#{class_name.singularize}[:#{name.pluralize.underscore}]}\n"
629
- else
630
- new_line.write " #{name.singularize.camelize(:lower)}: \"\#{#{class_name.singularize}[:#{name.singularize.underscore}]}\"\n"
631
- end
632
- when "bigint", "integer", "float", "boolean"
633
- new_line.write " #{name.singularize.camelize(:lower)}: \#{#{class_name.singularize}[:#{name.singularize.underscore}]}\n"
634
- end
635
- end
636
- end
637
- if table_check(line: line, class_name: class_name)
638
- @on = true
639
- end
640
- end
641
- end
642
- end
643
- end
644
-
645
- def rspec_mutation_params_response class_name: "souls"
646
- file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
647
- path = "./db/schema.rb"
648
- @on = false
649
- File.open(file_path, "a") do |new_line|
650
- File.open(path, "r") do |f|
651
- f.each_line.with_index do |line, i|
652
- if @on
653
- if line.include?("end") || line.include?("t.index")
654
- if @user_exist
655
- new_line.write <<-EOS
656
- }
657
- }
658
- }
659
- }
660
- )
661
- end
662
-
663
- subject(:result) do
664
- context = {
665
- user: user
666
- }
667
- SoulsApiSchema.execute(mutation, context: context).as_json
668
- end
669
-
670
- it "return #{class_name.camelize} Data" do
671
- begin
672
- a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
673
- raise unless a1.present?
674
- rescue
675
- raise StandardError, result
676
- end
677
- expect(a1).to include(
678
- "id" => be_a(String),
679
- EOS
680
- else
681
- new_line.write <<-EOS
682
- }
683
- }
684
- }
685
- }
686
- )
687
- end
688
-
689
- subject(:result) do
690
- SoulsApiSchema.execute(mutation).as_json
691
- end
692
-
693
- it "return #{class_name.camelize} Data" do
694
- begin
695
- a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
696
- raise unless a1.present?
697
- rescue
698
- raise StandardError, result
699
- end
700
- expect(a1).to include(
701
- "id" => be_a(String),
702
- EOS
703
- end
704
- break
705
- end
706
- _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
707
- array_true = line.include?("array: true")
708
- case name
709
- when "user_id", "created_at", "updated_at", /$*_id\z/
710
- next
711
- else
712
- if array_true
713
- new_line.write " #{name.pluralize.camelize(:lower)}\n"
714
- else
715
- new_line.write " #{name.singularize.camelize(:lower)}\n"
716
- end
717
- end
718
- end
719
- if table_check(line: line, class_name: class_name)
720
- @on = true
721
- end
722
- end
723
- end
724
- end
725
- end
726
-
727
- def rspec_mutation_end class_name: "souls"
728
- file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
729
- path = "./db/schema.rb"
730
- @on = false
731
- File.open(file_path, "a") do |new_line|
732
- File.open(path, "r") do |f|
733
- f.each_line.with_index do |line, i|
734
- if @on
735
- if line.include?("end") || line.include?("t.index")
736
- new_line.write <<~EOS
737
- )
738
- end
739
- end
740
- end
741
- EOS
742
- break
743
- end
744
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
745
- field ||= type_check type
746
- array_true = line.include?("array: true")
747
- case name
748
- when "user_id", "created_at", "updated_at", /$*_id\z/
749
- next
750
- else
751
- case type
752
- when "text", "date", "datetime"
753
- if array_true
754
- new_line.write " \"#{name.pluralize.camelize(:lower)}\" => be_all(String),\n"
755
- else
756
- new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(String),\n"
757
- end
758
- when "boolean"
759
- new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
760
- when "string", "bigint", "integer", "float"
761
- new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
762
- end
763
- end
764
- end
765
- if table_check(line: line, class_name: class_name)
766
- @on = true
767
- end
768
- end
769
- end
770
- end
771
- [file_path]
772
- end
773
-
774
- def rspec_mutation class_name: "souls"
775
- singularized_class_name = class_name.singularize
776
- rspec_mutation_head class_name: singularized_class_name
777
- rspec_mutation_after_head class_name: singularized_class_name
778
- rspec_mutation_params class_name: singularized_class_name
779
- rspec_mutation_params_response class_name: singularized_class_name
780
- rspec_mutation_end class_name: singularized_class_name
781
- end
782
-
783
- def rspec_query_head class_name: "souls"
784
- file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
785
- File.open(file_path, "w") do |f|
786
- f.write <<~EOS
787
- RSpec.describe \"#{class_name.camelize} Query テスト\" do
788
- describe "#{class_name.camelize} データを取得する" do
789
- EOS
790
- end
791
- end
792
-
793
- def rspec_query_after_head class_name: "souls"
794
- file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
795
- path = "./db/schema.rb"
796
- @on = false
797
- @user_exist = false
798
- @relation_params = []
799
- File.open(file_path, "a") do |new_line|
800
- File.open(path, "r") do |f|
801
- f.each_line.with_index do |line, i|
802
- if @on
803
- if line.include?("end") || line.include?("t.index")
804
- if @relation_params.empty?
805
- new_line.write <<-EOS
806
- let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
807
-
808
- let(:query) do
809
- data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
810
- %(query {
811
- #{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
812
- id
813
- EOS
814
- break
815
- else
816
- new_line.write <<-EOS
817
- let(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(", ")}) }
818
-
819
- let(:query) do
820
- data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
821
- %(query {
822
- #{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
823
- id
824
- EOS
825
- break
826
- end
827
- end
828
- _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
829
- case name
830
- when /$*_id\z/
831
- relation_col = name.gsub("_id", "")
832
- @relation_params << "#{name}: #{relation_col}.id"
833
- new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
834
- end
835
- end
836
- if table_check(line: line, class_name: class_name)
837
- @on = true
838
- end
839
- end
840
- end
841
- end
842
- end
843
-
844
- def rspec_query_params class_name: "souls"
845
- file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
846
- path = "./db/schema.rb"
847
- @on = false
848
- File.open(file_path, "a") do |new_line|
849
- File.open(path, "r") do |f|
850
- f.each_line.with_index do |line, i|
851
- if @on
852
- if line.include?("end") || line.include?("t.index")
853
- new_line.write <<-EOS
854
- }
855
- }
856
- )
857
- end
858
-
859
- subject(:result) do
860
- SoulsApiSchema.execute(query).as_json
861
- end
862
-
863
- it "return #{class_name.camelize} Data" do
864
- begin
865
- a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}")
866
- raise unless a1.present?
867
- rescue
868
- raise StandardError, result
869
- end
870
- expect(a1).to include(
871
- "id" => be_a(String),
872
- EOS
873
- break
874
- end
875
- _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
876
- case name
877
- when "user_id", "created_at", "updated_at", /$*_id\z/
878
- next
879
- else
880
- new_line.write " #{name.camelize(:lower)}\n"
881
- end
882
- end
883
- if table_check(line: line, class_name: class_name)
884
- @on = true
885
- end
886
- end
887
- end
888
- end
889
- end
890
-
891
- def rspec_query_end class_name: "souls"
892
- file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
893
- path = "./db/schema.rb"
894
- @on = false
895
- File.open(file_path, "a") do |new_line|
896
- File.open(path, "r") do |f|
897
- f.each_line.with_index do |line, i|
898
- if @on
899
- if line.include?("end") || line.include?("t.index")
900
- new_line.write <<~EOS
901
- )
902
- end
903
- end
904
- end
905
- EOS
906
- break
907
- end
908
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
909
- field ||= type_check type
910
- array_true = line.include?("array: true")
911
- case name
912
- when "user_id", "created_at", "updated_at", /$*_id\z/
913
- next
914
- else
915
- case type
916
- when "text", "date", "datetime"
917
- if array_true
918
- new_line.write " \"#{name.camelize(:lower)}\" => be_all(String),\n"
919
- else
920
- new_line.write " \"#{name.camelize(:lower)}\" => be_a(String),\n"
921
- end
922
- when "boolean"
923
- new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
924
- when "string", "bigint", "integer", "float"
925
- new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
926
- end
927
- end
928
- end
929
- if table_check(line: line, class_name: class_name)
930
- @on = true
931
- end
932
- end
933
- end
934
- end
935
- [file_path]
936
- end
937
-
938
- def rspec_query class_name: "souls"
939
- singularized_class_name = class_name.singularize
940
- rspec_query_head class_name: singularized_class_name
941
- rspec_query_after_head class_name: singularized_class_name
942
- rspec_query_params class_name: singularized_class_name
943
- rspec_query_end class_name: singularized_class_name
944
- end
945
-
946
- def get_end_point
947
- file_path = "./app/graphql/types/mutation_type.rb"
948
- File.open(file_path, "r") do |f|
949
- f.each_line.with_index do |line, i|
950
- return i if line.include?("end")
951
- end
952
- end
953
- end
954
-
955
- def get_tables
956
- path = "./db/schema.rb"
957
- tables = []
958
- File.open(path, "r") do |f|
959
- f.each_line.with_index do |line, i|
960
- tables << line.split("\"")[1] if line.include?("create_table")
961
- end
962
- end
963
- tables
964
- end
965
-
966
- def add_mutation_type class_name: "souls"
967
- # let's do this later
968
- end
969
-
970
- def add_query_type class_name: "souls"
971
- # let's do this later
972
- end
973
-
974
- def migrate class_name: "souls"
975
- singularized_class_name = class_name.singularize
976
- model_paths = model class_name: singularized_class_name
977
- type_paths = type class_name: singularized_class_name
978
- node_type_paths = node_type class_name: singularized_class_name
979
- resolver_paths = resolver class_name: singularized_class_name
980
- rspec_factory_paths = rspec_factory class_name: singularized_class_name
981
- rspec_model_paths = rspec_model class_name: singularized_class_name
982
- rspec_mutation_paths = rspec_mutation class_name: singularized_class_name
983
- rspec_query_paths = rspec_query class_name: singularized_class_name
984
- rspec_resolver_paths = rspec_resolver class_name: singularized_class_name
985
- query_path = query class_name: singularized_class_name
986
- mutation_path = mutation class_name: singularized_class_name
987
- [
988
- model: model_paths,
989
- type: type_paths,
990
- resolver: resolver_paths,
991
- node_type: node_type_paths,
992
- rspec_factory: rspec_factory_paths,
993
- rspec_model: rspec_model_paths,
994
- rspec_mutation: rspec_mutation_paths,
995
- rspec_query: rspec_query_paths,
996
- rspec_resolver: rspec_resolver_paths,
997
- query: query_path,
998
- mutation: mutation_path,
999
- add_query_type: [
1000
- " field :#{singularized_class_name}, resolver: Queries::#{singularized_class_name.camelize}",
1001
- " field :#{singularized_class_name.pluralize}, Types::#{singularized_class_name.camelize}Type.connection_type, null: true"
1002
- ],
1003
- add_mutation_type: [
1004
- " field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}",
1005
- " field :update_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Update#{singularized_class_name.camelize}",
1006
- " field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}",
1007
- " field :destroy_delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::DestroyDelete#{singularized_class_name.camelize}"
1008
- ],
1009
- add_resolver: [
1010
- " field :#{singularized_class_name}_search, resolver: Resolvers::#{singularized_class_name.camelize}Search"
1011
- ]
1012
- ]
1013
- end
1014
-
1015
- def single_migrate class_name: "user"
1016
- puts "◆◆◆ Let's Auto Generate CRUD API ◆◆◆\n"
1017
- result = migrate class_name: class_name
1018
- puts result[0][:model]
1019
- puts result[0][:type]
1020
- puts result[0][:resolver]
1021
- puts result[0][:node_type]
1022
- puts result[0][:rspec_factory]
1023
- puts result[0][:rspec_model]
1024
- puts result[0][:rspec_mutation]
1025
- puts result[0][:rspec_query]
1026
- puts result[0][:rspec_resolver]
1027
- puts result[0][:query]
1028
- puts result[0][:mutation]
1029
-
1030
- puts "\nAll files created from ./db/schema.rb"
1031
- puts "\n\n"
1032
- puts "##########################################################\n"
1033
- puts "# #\n"
1034
- puts "# Add These Lines at ./app/graphql/types/query_type.rb #\n"
1035
- puts "# #\n"
1036
- puts "##########################################################\n\n\n"
1037
- result[0][:add_query_type].each do |path|
1038
- puts path
1039
- end
1040
- puts "\n ## Resolvers\n\n"
1041
- result[0][:add_resolver].each do |path|
1042
- puts path
1043
- end
1044
- puts "\n ## Connection Type\n\n"
1045
- puts " def #{class_name.pluralize}"
1046
- puts " #{class_name.singularize.camelize}.all.order(id: :desc)"
1047
- puts " end\n\n\n"
1048
-
1049
- puts "#############################################################\n"
1050
- puts "# #\n"
1051
- puts "# Add These Lines at ./app/graphql/types/mutation_type.rb #\n"
1052
- puts "# #\n"
1053
- puts "#############################################################\n\n\n"
1054
- result[0][:add_mutation_type].each do |path|
1055
- puts path
1056
- end
1057
- end
1058
-
1059
- def migrate_all
1060
- puts "◆◆◆ Let's Auto Generate CRUD API ◆◆◆\n"
1061
- paths = get_tables.map do |class_name|
1062
- migrate class_name: class_name.singularize
1063
- end
1064
- puts "\n============== Model ======================\n\n"
1065
- paths.each do |class_name|
1066
- class_name.each do |path|
1067
- path[:model].each { |line| puts line }
1068
- end
1069
- end
1070
- puts "\n============== Type =======================\n\n"
1071
- paths.each do |class_name|
1072
- class_name.each do |path|
1073
- path[:type].each { |line| puts line }
1074
- end
1075
- end
1076
- puts "\n============== Resolver =======================\n\n"
1077
- paths.each do |class_name|
1078
- class_name.each do |path|
1079
- path[:resolver].each { |line| puts line }
1080
- end
1081
- end
1082
- puts "\n============== NodeType =======================\n\n"
1083
- paths.each do |class_name|
1084
- class_name.each do |path|
1085
- path[:node_type].each { |line| puts line }
1086
- end
1087
- end
1088
- puts "\n============== FactoryBot =================\n\n"
1089
- paths.each do |class_name|
1090
- class_name.each do |path|
1091
- path[:rspec_factory].each { |line| puts line }
1092
- end
1093
- end
1094
- puts "\n============== RspecModel =================\n\n"
1095
- paths.each do |class_name|
1096
- class_name.each do |path|
1097
- path[:rspec_model].each { |line| puts line }
1098
- end
1099
- end
1100
- puts "\n============== RspecMutation =================\n\n"
1101
- paths.each do |class_name|
1102
- class_name.each do |path|
1103
- path[:rspec_mutation].each { |line| puts line }
1104
- end
1105
- end
1106
- puts "\n============== RspecQuery =================\n\n"
1107
- paths.each do |class_name|
1108
- class_name.each do |path|
1109
- path[:rspec_query].each { |line| puts line }
1110
- end
1111
- end
1112
- puts "\n============== RspecResolver =================\n\n"
1113
- paths.each do |class_name|
1114
- class_name.each do |path|
1115
- path[:rspec_resolver].each { |line| puts line }
1116
- end
1117
- end
1118
- puts "\n============== Query ======================\n\n"
1119
- paths.each do |class_name|
1120
- class_name.each do |path|
1121
- path[:query].each { |line| puts line }
1122
- end
1123
- end
1124
- puts "\n============== Mutation ===================\n\n"
1125
- paths.each do |class_name|
1126
- class_name.each do |path|
1127
- path[:mutation].each { |line| puts line }
1128
- end
1129
- end
1130
- puts "\nAll files created from ./db/schema.rb"
1131
- puts "\n\n"
1132
- puts "\n##########################################################\n"
1133
- puts "# #\n"
1134
- puts "# Add These Lines at ./app/graphql/types/query_type.rb #\n"
1135
- puts "# #\n"
1136
- puts "##########################################################\n\n\n"
1137
- paths.each do |class_name|
1138
- class_name.each do |path|
1139
- path[:add_query_type].each { |line| puts line }
1140
- end
1141
- end
1142
- puts "\n ## Resolvers\n\n"
1143
- paths.each do |class_name|
1144
- class_name.each do |path|
1145
- path[:add_resolver].each { |line| puts line }
1146
- end
1147
- end
1148
- puts "\n ## Connection Type\n\n"
1149
- get_tables.each do |class_name|
1150
- puts " def #{class_name.pluralize}"
1151
- puts " #{class_name.singularize.camelize}.all.order(id: :desc)"
1152
- puts " end\n\n"
1153
- end
1154
- puts "\n#############################################################\n"
1155
- puts "# #\n"
1156
- puts "# Add These Lines at ./app/graphql/types/mutation_type.rb #\n"
1157
- puts "# #\n"
1158
- puts "#############################################################\n\n\n"
1159
- paths.each do |class_name|
1160
- class_name.each do |path|
1161
- path[:add_mutation_type].each { |line| puts line }
1162
- end
1163
- end
1164
- end
1165
49
  end
1166
50
  end
1167
51
  end