souls 0.18.0 → 0.20.3

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