souls 2.0.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -23
  3. data/lib/souls/cli/create/index.rb +0 -62
  4. data/lib/souls/cli/db/create_migration.rb +0 -1
  5. data/lib/souls/cli/db/index.rb +0 -2
  6. data/lib/souls/cli/delete/application.rb +2 -18
  7. data/lib/souls/cli/delete/job.rb +0 -1
  8. data/lib/souls/cli/delete/manager.rb +0 -1
  9. data/lib/souls/cli/delete/migration_file.rb +0 -1
  10. data/lib/souls/cli/generate/application.rb +2 -26
  11. data/lib/souls/cli/generate/job.rb +0 -1
  12. data/lib/souls/cli/generate/manager.rb +0 -1
  13. data/lib/souls/cli/generate/mutation.rb +2 -2
  14. data/lib/souls/cli/init/index.rb +0 -8
  15. data/lib/souls/cli/update/index.rb +0 -7
  16. data/lib/souls/cli/upgrade/index.rb +0 -1
  17. data/lib/souls/cli.rb +2 -20
  18. data/lib/souls/utils/index.rb +0 -13
  19. data/lib/souls/version.rb +1 -1
  20. data/lib/souls/versions/.souls_api_version +1 -1
  21. data/lib/souls/versions/.souls_worker_version +1 -1
  22. metadata +4 -25
  23. data/lib/souls/cli/db/create_migration_rbs.rb +0 -25
  24. data/lib/souls/cli/db/model_rbs.rb +0 -22
  25. data/lib/souls/cli/delete/connection_rbs.rb +0 -16
  26. data/lib/souls/cli/delete/edge_rbs.rb +0 -15
  27. data/lib/souls/cli/delete/job_rbs.rb +0 -22
  28. data/lib/souls/cli/delete/manager_rbs.rb +0 -17
  29. data/lib/souls/cli/delete/mutation_rbs.rb +0 -15
  30. data/lib/souls/cli/delete/query_rbs.rb +0 -16
  31. data/lib/souls/cli/delete/resolver_rbs.rb +0 -16
  32. data/lib/souls/cli/delete/type_rbs.rb +0 -16
  33. data/lib/souls/cli/generate/connection_rbs.rb +0 -25
  34. data/lib/souls/cli/generate/edge_rbs.rb +0 -28
  35. data/lib/souls/cli/generate/job_rbs.rb +0 -40
  36. data/lib/souls/cli/generate/manager_rbs.rb +0 -32
  37. data/lib/souls/cli/generate/mutation_rbs.rb +0 -241
  38. data/lib/souls/cli/generate/query_rbs.rb +0 -38
  39. data/lib/souls/cli/generate/resolver_rbs.rb +0 -42
  40. data/lib/souls/cli/generate/type_rbs.rb +0 -56
  41. data/lib/souls/cli/update/mutation_rbs.rb +0 -126
  42. data/lib/souls/cli/update/type_rbs.rb +0 -44
  43. data/lib/souls/cli/upgrade/submodule.rb +0 -8
@@ -1,22 +0,0 @@
1
- module SOULs
2
- class Delete < Thor
3
- desc "job_rbs [CLASS_NAME]", "Delete SOULs Job Mutation RBS Template"
4
- def job_rbs(class_name)
5
- file_path = ""
6
- worker_name = FileUtils.pwd.split("/").last
7
- if worker_name == "api" || FileUtils.pwd.split("/")[-2] != "apps"
8
- raise(SOULs::CLIException, "This task must be run from within a worker directory")
9
- end
10
-
11
- Dir.chdir(SOULs.get_mother_path.to_s) do
12
- singularized_class_name = class_name.underscore.singularize
13
- file_dir = "./sig/#{worker_name}/app/graphql/queries/"
14
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
15
- file_path = "#{file_dir}#{singularized_class_name}.rbs"
16
- FileUtils.rm_f(file_path)
17
- SOULs::Painter.delete_file(file_path.to_s)
18
- end
19
- file_path
20
- end
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- module SOULs
2
- class Delete < Thor
3
- desc "manager_rbs [CLASS_NAME]", "Delete SOULs Manager RBS Template"
4
- method_option :mutation, aliases: "--mutation", required: true, desc: "Mutation File Name"
5
- def manager_rbs(class_name)
6
- file_path = ""
7
- singularized_class_name = class_name.underscore.singularize
8
- Dir.chdir(SOULs.get_mother_path.to_s) do
9
- file_dir = "./sig/api/app/graphql/mutations/managers/#{singularized_class_name}_manager"
10
- file_path = "#{file_dir}/#{options[:mutation]}.rbs"
11
- FileUtils.rm_f(file_path)
12
- SOULs::Painter.delete_file(file_path.to_s)
13
- end
14
- file_path
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- module SOULs
2
- class Delete < Thor
3
- desc "mutation_rbs [CLASS_NAME]", "Delete GraphQL Mutation RBS"
4
- def mutation_rbs(class_name)
5
- singularized_class_name = class_name.underscore.singularize
6
- file_path = ""
7
- Dir.chdir(SOULs.get_mother_path.to_s) do
8
- file_dir = "./sig/api/app/graphql/mutations/base/#{singularized_class_name}"
9
- FileUtils.rm_rf(file_dir)
10
- end
11
- SOULs::Painter.delete_file(file_path.to_s)
12
- file_path
13
- end
14
- end
15
- end
@@ -1,16 +0,0 @@
1
- module SOULs
2
- class Delete < Thor
3
- desc "query_rbs [CLASS_NAME]", "Delete GraphQL Query RBS"
4
- def query_rbs(class_name)
5
- file_path = ""
6
- Dir.chdir(SOULs.get_mother_path.to_s) do
7
- file_dir = "./sig/api/app/graphql/queries/"
8
- singularized_class_name = class_name.underscore.singularize
9
- file_path = "#{file_dir}#{singularized_class_name}*.rbs"
10
- FileUtils.rm_f(file_path)
11
- SOULs::Painter.delete_file(file_path.to_s)
12
- file_path
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module SOULs
2
- class Delete < Thor
3
- desc "resolver_rbs [CLASS_NAME]", "Delete GraphQL Resolver RBS"
4
- def resolver_rbs(class_name)
5
- singularized_class_name = class_name.underscore.singularize
6
- file_path = ""
7
- Dir.chdir(SOULs.get_mother_path.to_s) do
8
- file_dir = "./sig/api/app/graphql/resolvers"
9
- file_path = "#{file_dir}/#{singularized_class_name}_search.rbs"
10
- FileUtils.rm_f(file_path)
11
- end
12
- SOULs::Painter.delete_file(file_path.to_s)
13
- file_path
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module SOULs
2
- class Delete < Thor
3
- desc "type_rbs [CLASS_NAME]", "Delete GraphQL Type RBS"
4
- def type_rbs(class_name)
5
- singularized_class_name = class_name.underscore.singularize
6
- file_path = ""
7
- Dir.chdir(SOULs.get_mother_path.to_s) do
8
- file_dir = "./sig/api/app/graphql/types"
9
- file_path = "#{file_dir}/#{singularized_class_name}_type.rbs"
10
- FileUtils.rm_f(file_path)
11
- end
12
- SOULs::Painter.delete_file(file_path.to_s)
13
- file_path
14
- end
15
- end
16
- end
@@ -1,25 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "connection_rbs [CLASS_NAME]", "Generate GraphQL Connection RBS from schema.rb"
4
- def connection_rbs(class_name)
5
- file_path = ""
6
- Dir.chdir(SOULs.get_mother_path.to_s) do
7
- file_dir = "./sig/api/app/graphql/types/connections/"
8
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
- singularized_class_name = class_name.underscore.singularize
10
- file_path = "#{file_dir}#{singularized_class_name}_connection.rbs"
11
- File.open(file_path, "w") do |f|
12
- f.write(<<~TEXT)
13
- module Types
14
- class #{singularized_class_name.camelize}Connection < Types::BaseConnection
15
- def self.edge_type: (*untyped) -> untyped
16
- end
17
- end
18
- TEXT
19
- end
20
- SOULs::Painter.create_file(file_path.to_s)
21
- end
22
- file_path
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "edge_rbs [CLASS_NAME]", "Generate GraphQL Edge RBS from schema.rb"
4
- def edge_rbs(class_name)
5
- file_path = ""
6
- Dir.chdir(SOULs.get_mother_path.to_s) do
7
- file_dir = "./sig/api/app/graphql/types/edges/"
8
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
9
- singularized_class_name = class_name.underscore.singularize
10
- file_path = "#{file_dir}#{singularized_class_name}_edge.rbs"
11
- File.open(file_path, "w") do |f|
12
- f.write(<<~TEXT)
13
- module Types
14
- class #{singularized_class_name.camelize}Edge < Types::BaseEdge
15
- def self.edge_type: (*untyped) -> untyped
16
- def self.node_type: (*untyped) -> untyped
17
- def self.global_id_field: (*untyped) -> untyped
18
- def self.connection_type: ()-> untyped
19
- end
20
- end
21
- TEXT
22
- end
23
- SOULs::Painter.create_file(file_path.to_s)
24
- end
25
- file_path
26
- end
27
- end
28
- end
@@ -1,40 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "job_rbs [CLASS_NAME]", "Generate SOULs Job Mutation RBS Template"
4
- def job_rbs(class_name)
5
- file_path = ""
6
- worker_name = FileUtils.pwd.split("/").last
7
- Dir.chdir(SOULs.get_mother_path.to_s) do
8
- singularized_class_name = class_name.underscore.singularize
9
- file_dir = "./sig/#{worker_name}/app/graphql/queries/"
10
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
11
- file_path = "#{file_dir}#{singularized_class_name}.rbs"
12
- sig_type_path = "./sig/#{worker_name}/app/graphql/types"
13
- FileUtils.mkdir_p(sig_type_path) unless Dir.exist?(sig_type_path)
14
- type_file_path = "#{sig_type_path}/#{singularized_class_name}_type.rbs"
15
- File.open(file_path, "w") do |f|
16
- f.write(<<~TEXT)
17
- module Queries
18
- class #{singularized_class_name.camelize} < BaseQuery
19
- def self.description: (String) -> untyped
20
- def self.field: (:response, String, null: false) -> untyped
21
- def self.type: (untyped, null: false) -> untyped
22
- end
23
- end
24
- TEXT
25
- end
26
- File.open(type_file_path, "w") do |f|
27
- f.write(<<~TEXT)
28
- module Types
29
- class #{singularized_class_name.camelize}Type < SOULs::Types::BaseObject
30
- def self.field: (:response, String, null: true) -> untyped
31
- end
32
- end
33
- TEXT
34
- end
35
- SOULs::Painter.create_file(file_path.to_s)
36
- end
37
- file_path
38
- end
39
- end
40
- end
@@ -1,32 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "manager_rbs [CLASS_NAME]", "Generate SOULs Manager RBS Template"
4
- method_option :mutation, aliases: "--mutation", required: true, desc: "Mutation File Name"
5
- def manager_rbs(class_name)
6
- file_path = ""
7
- singularized_class_name = class_name.underscore.singularize
8
- Dir.chdir(SOULs.get_mother_path.to_s) do
9
- file_dir = "./sig/api/app/graphql/mutations/managers/#{singularized_class_name}_manager"
10
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
11
- file_path = "#{file_dir}/#{options[:mutation]}.rbs"
12
- File.open(file_path, "w") do |f|
13
- f.write(<<~TEXT)
14
- module Mutations
15
- module Managers
16
- module #{singularized_class_name.camelize}Manager
17
- class #{options[:mutation].singularize.camelize} < BaseMutation
18
- def self.description: (String)-> untyped
19
- def self.argument: (untyped, untyped, untyped)-> untyped
20
- def self.field: (untyped, untyped, untyped)-> untyped
21
- end
22
- end
23
- end
24
- end
25
- TEXT
26
- SOULs::Painter.create_file(file_path.to_s)
27
- end
28
- end
29
- file_path
30
- end
31
- end
32
- end
@@ -1,241 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "mutation_rbs [CLASS_NAME]", "Generate GraphQL Mutation RBS from schema.rb"
4
- def mutation_rbs(class_name)
5
- singularized_class_name = class_name.underscore.singularize
6
- create_rbs_mutation(class_name: singularized_class_name)
7
- update_rbs_mutation(class_name: singularized_class_name)
8
- delete_rbs_mutation(class_name: singularized_class_name)
9
- destroy_delete_rbs_mutation(class_name: singularized_class_name)
10
- end
11
-
12
- private
13
-
14
- def create_rbs_mutation(class_name: "user")
15
- file_path = ""
16
- Dir.chdir(SOULs.get_mother_path.to_s) do
17
- file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
18
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
19
- file_path = "#{file_dir}/create_#{class_name}.rbs"
20
- raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
21
-
22
- params = SOULs.get_relation_params(class_name:, col: "mutation")
23
- File.open(file_path, "w") do |f|
24
- f.write(<<~TEXT)
25
- class Boolean
26
- end
27
- module Mutations
28
- module Base
29
- module #{class_name.camelize}
30
- class Create#{class_name.camelize} < BaseMutation
31
- String: String
32
- Boolean: Boolean
33
- Integer: Integer
34
- def resolve: ({
35
- TEXT
36
- end
37
- File.open(file_path, "a") do |f|
38
- params[:params].each_with_index do |param, i|
39
- type = SOULs.rbs_type_check(param[:type])
40
- type = "[#{type}]" if param[:array]
41
- if i == params[:params].size - 1
42
- f.write(" #{param[:column_name]}: #{type}?\n")
43
- elsif param[:column_name].match?(/$*_id\z/)
44
- f.write(" #{param[:column_name]}: String?,\n")
45
- else
46
- f.write(" #{param[:column_name]}: #{type}?,\n")
47
- end
48
- end
49
- end
50
- # rubocop:disable Layout/LineLength
51
- File.open(file_path, "a") do |f|
52
- f.write(" }) -> ({ :#{class_name}_edge => { :node => String } } | ::GraphQL::ExecutionError )\n\n")
53
- end
54
- # rubocop:enable Layout/LineLength
55
-
56
- File.open(file_path, "a") do |f|
57
- params[:params].each_with_index do |param, i|
58
- type = SOULs.type_check(param[:type])
59
- rbs_type = SOULs.rbs_type_check(param[:type])
60
- type = "[#{type}]" if param[:array]
61
- if i.zero?
62
- if param[:column_name].match?(/$*_id\z/)
63
- f.write(
64
- " def self.argument: (:#{param[:column_name]}, String, " \
65
- "required: false ) -> #{rbs_type}\n"
66
- )
67
- else
68
- f.write(
69
- " def self.argument: (:#{param[:column_name]}, #{type}, " \
70
- "required: false ) -> #{rbs_type}\n"
71
- )
72
- end
73
- elsif param[:column_name].match?(/$*_id\z/)
74
- f.write(" | (:#{param[:column_name]}, String, required: false ) -> String\n")
75
- else
76
- f.write(
77
- " | (:#{param[:column_name]}, #{type}, " \
78
- "required: false ) -> #{rbs_type}\n"
79
- )
80
- end
81
- end
82
- end
83
-
84
- File.open(file_path, "a") do |f|
85
- f.write(<<~TEXT)
86
-
87
- def self.field: (*untyped) -> String
88
- attr_accessor context: {user:{
89
- id: Integer,
90
- username: String,
91
- email: String
92
- }}
93
- end
94
- end
95
- end
96
- end
97
- TEXT
98
- end
99
- end
100
- SOULs::Painter.create_file(file_path.to_s)
101
- file_path
102
- end
103
-
104
- def update_rbs_mutation(class_name: "user")
105
- file_path = ""
106
- Dir.chdir(SOULs.get_mother_path.to_s) do
107
- file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
108
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
109
- file_path = "#{file_dir}/update_#{class_name}.rbs"
110
- params = SOULs.get_relation_params(class_name:, col: "mutation")
111
- params[:params] << { column_name: "id", type: "string", array: false }
112
- File.open(file_path, "w") do |f|
113
- f.write(<<~TEXT)
114
- module Mutations
115
- module Base
116
- module #{class_name.camelize}
117
- class Update#{class_name.camelize} < BaseMutation
118
- String: String
119
- Boolean: Boolean
120
- Integer: Integer
121
- def resolve: ({
122
- id: String,
123
- TEXT
124
- end
125
- File.open(file_path, "a") do |f|
126
- cols = params[:params].reject { |n| n[:column_name] == "user_id" }
127
- cols.each_with_index do |param, i|
128
- type = SOULs.rbs_type_check(param[:type])
129
- type = "[#{type}]" if param[:array]
130
- type = "String" if param[:column_name].match?(/$*_id\z/)
131
-
132
- if i == params[:params].size - 1
133
- f.write(" #{param[:column_name]}: #{type}?\n")
134
- else
135
- f.write(" #{param[:column_name]}: #{type}?,\n")
136
- end
137
- end
138
- end
139
- # rubocop:disable Layout/LineLength
140
- File.open(file_path, "a") do |f|
141
- f.write(" }) -> ({ :#{class_name}_edge => { :node => String } } | ::GraphQL::ExecutionError )\n\n")
142
- end
143
- # rubocop:enable Layout/LineLength
144
-
145
- File.open(file_path, "a") do |f|
146
- cols = params[:params].reject { |n| n[:column_name] == "user_id" }
147
- cols.each_with_index do |param, i|
148
- type = SOULs.type_check(param[:type])
149
- rbs_type = SOULs.rbs_type_check(param[:type])
150
- type = "[#{type}]" if param[:array]
151
- type = "String" if param[:column_name].match?(/$*_id\z/)
152
- rbs_type = "String" if param[:column_name].match?(/$*_id\z/)
153
-
154
- required = param[:column_name] == "id" ? "required: true" : "required: false"
155
- if i.zero?
156
- f.write(" def self.argument: (:#{param[:column_name]}, #{type}, #{required} ) -> #{rbs_type}\n")
157
- else
158
- f.write(" | (:#{param[:column_name]}, #{type}, #{required} ) -> #{rbs_type}\n")
159
- end
160
- end
161
- end
162
-
163
- File.open(file_path, "a") do |f|
164
- f.write(<<~TEXT)
165
-
166
- def self.field: (*untyped) -> String
167
- attr_accessor context: {user:{
168
- id: Integer,
169
- username: String,
170
- email: String
171
- }}
172
- end
173
- end
174
- end
175
- end
176
- TEXT
177
- end
178
- end
179
- SOULs::Painter.create_file(file_path.to_s)
180
- file_path
181
- end
182
-
183
- def delete_rbs_mutation(class_name: "user")
184
- file_path = ""
185
- Dir.chdir(SOULs.get_mother_path.to_s) do
186
- file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
187
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
188
- file_path = "#{file_dir}/delete_#{class_name}.rbs"
189
- File.open(file_path, "w") do |f|
190
- f.write(<<~TEXT)
191
- module Mutations
192
- module Base
193
- module #{class_name.camelize}
194
- class Delete#{class_name.camelize}
195
- def resolve: ({
196
- id: String
197
- }) -> ( Hash[Symbol, untyped] | ::GraphQL::ExecutionError )
198
- #{' '}
199
- def self.argument: (*untyped) -> String
200
- def self.field: (*untyped) -> String
201
- end
202
- end
203
- end
204
- end
205
- TEXT
206
- end
207
- SOULs::Painter.create_file(file_path.to_s)
208
- end
209
- file_path
210
- end
211
-
212
- def destroy_delete_rbs_mutation(class_name: "user")
213
- file_path = ""
214
- Dir.chdir(SOULs.get_mother_path.to_s) do
215
- file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
216
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
217
- file_path = "#{file_dir}/destroy_delete_#{class_name}.rbs"
218
- File.open(file_path, "w") do |f|
219
- f.write(<<~TEXT)
220
- module Mutations
221
- module Base
222
- module #{class_name.camelize}
223
- class DestroyDelete#{class_name.camelize}
224
- def resolve: ({
225
- id: String
226
- }) -> ( Hash[Symbol, untyped] | ::GraphQL::ExecutionError )
227
- #{' '}
228
- def self.argument: (*untyped) -> String
229
- def self.field: (*untyped) -> String
230
- end
231
- end
232
- end
233
- end
234
- TEXT
235
- end
236
- SOULs::Painter.create_file(file_path.to_s)
237
- end
238
- file_path
239
- end
240
- end
241
- end
@@ -1,38 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "query_rbs [CLASS_NAME]", "Generate GraphQL Query RBS"
4
- def query_rbs(class_name)
5
- single_query_rbs(class_name)
6
- end
7
-
8
- private
9
-
10
- def single_query_rbs(class_name)
11
- file_path = ""
12
- Dir.chdir(SOULs.get_mother_path.to_s) do
13
- file_dir = "./sig/api/app/graphql/queries/"
14
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
15
- singularized_class_name = class_name.underscore.singularize
16
- file_path = "#{file_dir}#{singularized_class_name}.rbs"
17
- File.open(file_path, "w") do |f|
18
- f.write(<<~TEXT)
19
- module Queries
20
- class BaseQuery
21
- end
22
- class #{singularized_class_name.camelize} < Queries::BaseQuery
23
- def resolve: ({
24
- id: String?
25
- }) -> ( Hash[Symbol, ( String | Integer | bool )] | ::GraphQL::ExecutionError )
26
-
27
- def self.argument: (*untyped) -> String
28
- def self.type: (*untyped) -> String
29
- end
30
- end
31
- TEXT
32
- end
33
- SOULs::Painter.create_file(file_path.to_s)
34
- end
35
- file_path
36
- end
37
- end
38
- end
@@ -1,42 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "resolver_rbs [CLASS_NAME]", "Generate GraphQL Resolver RBS from schema.rb"
4
- def resolver_rbs(class_name)
5
- singularized_class_name = class_name.underscore.singularize
6
- file_path = ""
7
- Dir.chdir(SOULs.get_mother_path.to_s) do
8
- file_dir = "./sig/api/app/graphql/resolvers"
9
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
10
- file_path = "#{file_dir}/#{singularized_class_name}_search.rbs"
11
- raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
12
-
13
- File.open(file_path, "w") do |f|
14
- f.write(<<~TEXT)
15
- module Resolvers
16
- class BaseResolver
17
- end
18
- class #{singularized_class_name.camelize}Search < BaseResolver
19
- include SearchObject
20
- def self.scope: () ?{ () -> nil } -> [Hash[Symbol, untyped]]
21
- def self.type: (*untyped) -> String
22
- def self.option: (:filter, type: untyped, with: :apply_filter) -> String
23
- def self.description: (String) -> String
24
- def self.types: (*untyped) -> String
25
- def decode_global_key: (String value) -> Integer
26
- def apply_filter: (untyped scope, untyped value) -> untyped
27
-
28
- class #{singularized_class_name.camelize}Filter
29
- String: String
30
- Boolean: Boolean
31
- Integer: Integer
32
- end
33
- end
34
- end
35
- TEXT
36
- end
37
- end
38
- SOULs::Painter.create_file(file_path.to_s)
39
- file_path
40
- end
41
- end
42
- end
@@ -1,56 +0,0 @@
1
- module SOULs
2
- class Generate < Thor
3
- desc "type_rbs [CLASS_NAME]", "Generate GraphQL Type RBS from schema.rb"
4
- def type_rbs(class_name)
5
- singularized_class_name = class_name.underscore.singularize
6
- file_path = ""
7
- Dir.chdir(SOULs.get_mother_path.to_s) do
8
- file_dir = "./sig/api/app/graphql/types"
9
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
10
- file_path = "#{file_dir}/#{singularized_class_name}_type.rbs"
11
- raise(Thor::Error, "Type RBS already exist! #{file_path}") if File.exist?(file_path)
12
-
13
- params = SOULs.get_relation_params(class_name: singularized_class_name)
14
- File.open(file_path, "w") do |f|
15
- f.write(<<~TEXT)
16
- module Types
17
- class #{singularized_class_name.camelize}Type < BaseObject
18
- def self.implements: (*untyped) -> untyped
19
- def self.global_id_field: (:id) -> String
20
- TEXT
21
- end
22
- File.open(file_path, "a") do |f|
23
- params[:params].each_with_index do |param, i|
24
- type = SOULs.type_check(param[:type])
25
- type = "[#{type}]" if param[:array]
26
- rbs_type = SOULs.rbs_type_check(param[:type])
27
- if i.zero?
28
- if param[:column_name].match?(/$*_id\z/)
29
- col_name = param[:column_name].gsub("_id", "")
30
- f.write(" def self.field: (:#{col_name}, untyped, null: false) -> untyped\n")
31
- else
32
- f.write(" def self.field: (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
33
- end
34
- elsif param[:column_name].match?(/$*_id\z/)
35
- col_name = param[:column_name].gsub("_id", "")
36
- f.write(" | (:#{col_name}, untyped, null: false) -> untyped\n")
37
- else
38
- f.write(" | (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
39
- end
40
- end
41
- end
42
-
43
- File.open(file_path, "a") do |f|
44
- f.write(<<~TEXT)
45
- def self.edge_type: () -> untyped
46
- def self.connection_type: () -> untyped
47
- end
48
- end
49
- TEXT
50
- end
51
- end
52
- SOULs::Painter.create_file(file_path.to_s)
53
- file_path
54
- end
55
- end
56
- end