souls 0.55.2 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cadd8e85a9df7d2bbc5b4a276d163e2fde33ce2549f12505f624c3f16d297585
4
- data.tar.gz: 0c7f9f8e2139a2fc37271fcce9e60ac65e5b437c6b425be7cd30bdee269f95c5
3
+ metadata.gz: 8b11027355d2156abdaa8807eda594fd4ba96fde1fdb0cf546e6f5f1cd34487a
4
+ data.tar.gz: cba26dd0ea25bafe8ecce20ef66a10f1f2ef86f0bfb0b5f6c54594d332c3400c
5
5
  SHA512:
6
- metadata.gz: c1cff34a13bab301ea31b905e3a75f05b401c60a1a2d94800e3d2ff49a47f21a2ade571df14b0ac916c3b50c3e1fa8336703232c7606b1dd64c5233f9fb8d2e0
7
- data.tar.gz: bcef4c3899794142b56a89ae306490be66661d60ebd841e815a24415c6200330211ff5824a1eb1ab600dd3eccbec3561078f3f20649e4cb30151a35811f53d95
6
+ metadata.gz: 5bd75f70b0284d5ecab2a2eda7a013557db7578d69caec27dd9296c3649838413bfe011ea573a63fb8ce94cb9469bb7882b37951de7ec18ff84dd87e03de94ca
7
+ data.tar.gz: 61b91ab91c7cd6b277718b3f9f6bba5451d956d386099a941e2f0f9e4632ad69cec3d897804b36fc0ebb9c0a528d6f2008fdc1140d2e3b01bd7d93874f7aba42
data/README.md CHANGED
@@ -84,7 +84,7 @@ And Create Your APP
84
84
 
85
85
  Check your GraphQL PlayGround
86
86
 
87
- (localhost:4000/playground)[localhost:4000/playground]
87
+ [localhost:4000/playground](localhost:4000/playground)
88
88
 
89
89
  ## Gemfile 自動更新アップデート
90
90
 
data/exe/souls CHANGED
@@ -3,18 +3,7 @@ require "souls"
3
3
  require "thor"
4
4
  begin
5
5
  souls_command = ARGV[0]
6
- require("./config/souls") unless [
7
- "new",
8
- "docker",
9
- "-v",
10
- "deploy",
11
- "help",
12
- "api",
13
- "create",
14
- "worker",
15
- "",
16
- nil
17
- ].include?(souls_command)
6
+ require("./config/souls") unless ["new", "docker", "-v", "help", "", nil].include?(souls_command)
18
7
  rescue StandardError
19
8
  raise(StandardError, "No confif! Please make `./config/souls.rb` File!")
20
9
  end
@@ -4,18 +4,26 @@ module Souls
4
4
  def scaffold(class_name)
5
5
  singularized_class_name = class_name.singularize
6
6
  model(singularized_class_name)
7
+ model_rbs(singularized_class_name)
7
8
  type(singularized_class_name)
9
+ type_rbs(singularized_class_name)
10
+ query(singularized_class_name)
11
+ query_rbs(singularized_class_name)
12
+ mutation(singularized_class_name)
13
+ mutation_rbs(singularized_class_name)
14
+ policy(singularized_class_name)
15
+ policy_rbs(singularized_class_name)
8
16
  edge(singularized_class_name)
17
+ edge_rbs(singularized_class_name)
9
18
  connection(singularized_class_name)
19
+ connection_rbs(singularized_class_name)
10
20
  resolver(singularized_class_name)
21
+ resolver_rbs(singularized_class_name)
11
22
  rspec_factory(singularized_class_name)
12
23
  rspec_model(singularized_class_name)
13
24
  rspec_mutation(singularized_class_name)
14
25
  rspec_query(singularized_class_name)
15
26
  rspec_resolver(singularized_class_name)
16
- query(singularized_class_name)
17
- mutation(singularized_class_name)
18
- policy(singularized_class_name)
19
27
  rspec_policy(singularized_class_name)
20
28
  true
21
29
  rescue Thor::Error => e
@@ -1,19 +1,24 @@
1
1
  module Souls
2
2
  class Generate < Thor
3
- desc "connection [CLASS_NAME]", "Generate GraphQL Connection from schema.rb"
4
- def connection(class_name)
5
- file_dir = "./app/graphql/types/connections/"
6
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
7
- singularized_class_name = class_name.underscore.singularize
8
- file_path = "./app/graphql/types/connections/#{singularized_class_name}_connection.rb"
9
- File.open(file_path, "w") do |f|
10
- f.write(<<~TEXT)
11
- class Types::#{singularized_class_name.camelize}Connection < Types::BaseConnection
12
- edge_type(Types::#{singularized_class_name.camelize}Edge)
13
- end
14
- TEXT
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 edge_type: (*untyped) -> untyped
16
+ end
17
+ end
18
+ TEXT
19
+ end
20
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
15
21
  end
16
- puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
17
22
  file_path
18
23
  rescue Thor::Error => e
19
24
  raise(Thor::Error, e)
@@ -0,0 +1,30 @@
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 < BaseObject
15
+ def self.implements: (*untyped) -> untyped
16
+ def self.global_id_field: (*untyped) -> untyped
17
+ def self.field: (*untyped) -> untyped
18
+ def self.connection_type: ()-> untyped
19
+ end
20
+ end
21
+ TEXT
22
+ end
23
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
24
+ end
25
+ file_path
26
+ rescue Thor::Error => e
27
+ raise(Thor::Error, e)
28
+ end
29
+ end
30
+ end
@@ -1,26 +1,12 @@
1
- require_relative "./model"
2
- require_relative "./mutation"
3
- require_relative "./policy"
4
- require_relative "./query"
5
- require_relative "./resolver"
6
- require_relative "./rspec_factory"
7
- require_relative "./rspec_model"
8
- require_relative "./rspec_mutation"
9
- require_relative "./rspec_policy"
10
- require_relative "./rspec_query"
11
- require_relative "./rspec_resolver"
12
- require_relative "./type"
13
- require_relative "./edge"
14
- require_relative "./connection"
15
- require_relative "./application"
16
- require_relative "./manager"
1
+ require_paths = []
2
+ dev_path = "lib/souls/api/generate/*"
3
+ gem_path = "#{Gem.dir}/gems/souls-#{Souls::VERSION}/lib/souls/api/generate/*"
4
+ file_paths = File.exist?("souls.gemspec") ? dev_path : gem_path
5
+ Dir[file_paths].map do |n|
6
+ next if n.include?("index.rb")
17
7
 
18
- # require_paths = []
19
- # Dir["lib/souls/api/generate/*"].map do |n|
20
- # next if n.include?("index.rb")
21
-
22
- # require_paths << n.split("/").last.gsub(".rb", "")
23
- # end
24
- # require_paths.each do |path|
25
- # require_relative "./#{path}"
26
- # end
8
+ require_paths << n.split("/").last.gsub(".rb", "")
9
+ end
10
+ require_paths.each do |path|
11
+ require_relative "./#{path}"
12
+ end
@@ -0,0 +1,26 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "model_rbs [CLASS_NAME]", "Generate GraphQL Model RBS from schema.rb"
4
+ def model_rbs(class_name)
5
+ file_path = ""
6
+ Dir.chdir(Souls.get_mother_path.to_s) do
7
+ file_dir = "./sig/api/app/graphql/types/models/"
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}_model.rbs"
11
+ File.open(file_path, "w") do |f|
12
+ f.write(<<~TEXT)
13
+ module Types
14
+ class #{singularized_class_name.camelize} < ActiveRecord::Base
15
+ end
16
+ end
17
+ TEXT
18
+ end
19
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
20
+ end
21
+ file_path
22
+ rescue Thor::Error => e
23
+ raise(Thor::Error, e)
24
+ end
25
+ end
26
+ end
@@ -56,7 +56,8 @@ module Souls
56
56
  new_line.write(<<-TEXT)
57
57
 
58
58
  def resolve args
59
- args[:user_id] = context[:user].id
59
+ params = args.dup
60
+ params[:user_id] = context[:user][:id]
60
61
  TEXT
61
62
  else
62
63
  new_line.write(<<-TEXT)
@@ -150,14 +151,15 @@ module Souls
150
151
  new_line.write(<<-TEXT)
151
152
 
152
153
  def resolve args
153
- args[:user_id] = context[:user].id
154
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
154
+ params = args.dup
155
+ params[:user_id] = context[:user][:id]
156
+ _, params[:id] = SoulsApiSchema.from_global_id(args[:id])
155
157
  TEXT
156
158
  else
157
159
  new_line.write(<<-TEXT)
158
160
 
159
161
  def resolve args
160
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
162
+ _, params[:id] = SoulsApiSchema.from_global_id(args[:id])
161
163
  TEXT
162
164
  end
163
165
  break
@@ -190,7 +192,7 @@ module Souls
190
192
  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
191
193
  relation_params.each do |params_name|
192
194
  File.open(file_path, "a") do |new_line|
193
- new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
195
+ new_line.write(" _, params[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
194
196
  end
195
197
  end
196
198
  true
@@ -200,9 +202,9 @@ module Souls
200
202
  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
201
203
  File.open(file_path, "a") do |new_line|
202
204
  new_line.write(<<~TEXT)
203
- #{class_name} = ::#{class_name.camelize}.find args[:id]
204
- #{class_name}.update args
205
- { #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
205
+ #{class_name} = ::#{class_name.camelize}.find params[:id]
206
+ #{class_name}.update params
207
+ { #{class_name}_edge: { node: ::#{class_name.camelize}.find(params[:id]) } }
206
208
  rescue StandardError => error
207
209
  GraphQL::ExecutionError.new(error.message)
208
210
  end
@@ -0,0 +1,220 @@
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
+ rescue Thor::Error => e
11
+ raise(Thor::Error, e)
12
+ end
13
+
14
+ private
15
+
16
+ def create_rbs_mutation(class_name: "user")
17
+ file_path = ""
18
+ Dir.chdir(Souls.get_mother_path.to_s) do
19
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
20
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
21
+ file_path = "#{file_dir}/create_#{class_name}.rbs"
22
+ raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
23
+
24
+ params = Souls.get_relation_params(class_name: class_name, col: "mutation")
25
+ File.open(file_path, "w") do |f|
26
+ f.write(<<~TEXT)
27
+ class Boolean
28
+ end
29
+ module Mutations
30
+ module Base
31
+ module #{class_name.camelize}
32
+ class Create#{class_name.camelize} < BaseMutation
33
+ String: String
34
+ Boolean: Boolean
35
+ Integer: Integer
36
+ def resolve: ({
37
+ TEXT
38
+ end
39
+ File.open(file_path, "a") do |f|
40
+ params[:params].each_with_index do |param, i|
41
+ type = Souls.rbs_type_check(param[:type])
42
+ type = "[#{type}]" if param[:array]
43
+ if i == params[:params].size - 1
44
+ f.write(" #{param[:column_name]}: #{type}?\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
+ f.write(" def self.argument: (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
63
+ else
64
+ f.write(" | (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
65
+ end
66
+ end
67
+ end
68
+
69
+ File.open(file_path, "a") do |f|
70
+ f.write(<<~TEXT)
71
+
72
+ def self.field: (*untyped) -> String
73
+ attr_accessor context: {user:{
74
+ id: Integer,
75
+ username: String,
76
+ email: String
77
+ }}
78
+ end
79
+ end
80
+ end
81
+ end
82
+ TEXT
83
+ end
84
+ end
85
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
86
+ file_path
87
+ rescue Thor::Error => e
88
+ raise(Thor::Error, e)
89
+ end
90
+
91
+ def update_rbs_mutation(class_name: "user")
92
+ file_path = ""
93
+ Dir.chdir(Souls.get_mother_path.to_s) do
94
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
95
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
96
+ file_path = "#{file_dir}/update_#{class_name}.rbs"
97
+ params = Souls.get_relation_params(class_name: class_name, col: "mutation")
98
+ params[:params] << { column_name: "id", type: "string", array: false }
99
+ File.open(file_path, "w") do |f|
100
+ f.write(<<~TEXT)
101
+ module Mutations
102
+ module Base
103
+ module #{class_name.camelize}
104
+ class Update#{class_name.camelize} < BaseMutation
105
+ def resolve: ({
106
+ TEXT
107
+ end
108
+ File.open(file_path, "a") do |f|
109
+ params[:params].each_with_index do |param, i|
110
+ type = Souls.rbs_type_check(param[:type])
111
+ type = "[#{type}]" if param[:array]
112
+ if i == params[:params].size - 1
113
+ f.write(" #{param[:column_name]}: #{type}?\n")
114
+ else
115
+ f.write(" #{param[:column_name]}: #{type}?,\n")
116
+ end
117
+ end
118
+ end
119
+ # rubocop:disable Layout/LineLength
120
+ File.open(file_path, "a") do |f|
121
+ f.write(" }) -> ({ :#{class_name}_edge => { :node => String } } | ::GraphQL::ExecutionError )\n\n")
122
+ end
123
+ # rubocop:enable Layout/LineLength
124
+
125
+ File.open(file_path, "a") do |f|
126
+ params[:params].each_with_index do |param, i|
127
+ type = Souls.type_check(param[:type])
128
+ rbs_type = Souls.rbs_type_check(param[:type])
129
+ type = "[#{type}]" if param[:array]
130
+ if i.zero?
131
+ f.write(" def self.argument: (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
132
+ else
133
+ f.write(" | (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
134
+ end
135
+ end
136
+ end
137
+
138
+ File.open(file_path, "a") do |f|
139
+ f.write(<<~TEXT)
140
+
141
+ def self.field: (*untyped) -> String
142
+ attr_accessor context: {user:{
143
+ id: Integer,
144
+ username: String,
145
+ email: String
146
+ }}
147
+ end
148
+ end
149
+ end
150
+ end
151
+ TEXT
152
+ end
153
+ end
154
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
155
+ file_path
156
+ end
157
+
158
+ def delete_rbs_mutation(class_name: "user")
159
+ file_path = ""
160
+ Dir.chdir(Souls.get_mother_path.to_s) do
161
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
162
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
163
+ file_path = "#{file_dir}/delete_#{class_name}.rbs"
164
+ File.open(file_path, "w") do |f|
165
+ f.write(<<~TEXT)
166
+ module Mutations
167
+ module Base
168
+ module #{class_name.camelize}
169
+ class Delete#{class_name.camelize}
170
+ def resolve: ({
171
+ id: String
172
+ }) -> ( Hash[Symbol, untyped] | ::GraphQL::ExecutionError )
173
+ #{' '}
174
+ def self.argument: (*untyped) -> String
175
+ def self.field: (*untyped) -> String
176
+ end
177
+ end
178
+ end
179
+ end
180
+ TEXT
181
+ end
182
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
183
+ end
184
+ file_path
185
+ rescue Thor::Error => e
186
+ raise(Thor::Error, e)
187
+ end
188
+
189
+ def destroy_delete_rbs_mutation(class_name: "user")
190
+ file_path = ""
191
+ Dir.chdir(Souls.get_mother_path.to_s) do
192
+ file_dir = "./sig/api/app/graphql/mutations/base/#{class_name}"
193
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
194
+ file_path = "#{file_dir}/destroy_delete_#{class_name}.rbs"
195
+ File.open(file_path, "w") do |f|
196
+ f.write(<<~TEXT)
197
+ module Mutations
198
+ module Base
199
+ module #{class_name.camelize}
200
+ class DestroyDelete#{class_name.camelize}
201
+ def resolve: ({
202
+ id: String
203
+ }) -> ( Hash[Symbol, untyped] | ::GraphQL::ExecutionError )
204
+ #{' '}
205
+ def self.argument: (*untyped) -> String
206
+ def self.field: (*untyped) -> String
207
+ end
208
+ end
209
+ end
210
+ end
211
+ TEXT
212
+ end
213
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
214
+ end
215
+ file_path
216
+ rescue Thor::Error => e
217
+ raise(Thor::Error, e)
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,35 @@
1
+ module Souls
2
+ class Generate < Thor
3
+ desc "policy_rbs [CLASS_NAME]", "Generate Policy RBS"
4
+ def policy_rbs(class_name)
5
+ file_path = ""
6
+ Dir.chdir(Souls.get_mother_path.to_s) do
7
+ file_dir = "./sig/api/app/graphql/types/policies/"
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}_policy.rbs"
11
+ File.open(file_path, "w") do |f|
12
+ f.write(<<~TEXT)
13
+ class #{singularized_class_name.camelize}Policy
14
+ @user: untyped
15
+
16
+ def show?: -> true
17
+ def index?: -> true
18
+ def create?: -> bool
19
+ def update?: -> bool
20
+ def delete?: -> bool
21
+
22
+ private
23
+ def user_permissions?: -> untyped
24
+ def admin_permissions?: -> untyped
25
+ end
26
+ TEXT
27
+ end
28
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
29
+ end
30
+ file_path
31
+ rescue Thor::Error => e
32
+ raise(Thor::Error, e)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,67 @@
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
+ queries_rbs(class_name)
7
+ end
8
+
9
+ private
10
+
11
+ def single_query_rbs(class_name)
12
+ file_path = ""
13
+ Dir.chdir(Souls.get_mother_path.to_s) do
14
+ file_dir = "./sig/api/app/graphql/queries/"
15
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
16
+ singularized_class_name = class_name.underscore.singularize
17
+ file_path = "#{file_dir}#{singularized_class_name}.rbs"
18
+ File.open(file_path, "w") do |f|
19
+ f.write(<<~TEXT)
20
+ module Queries
21
+ class BaseQuery
22
+ end
23
+ class #{singularized_class_name.camelize} < Queries::BaseQuery
24
+ def resolve: ({
25
+ id: String?
26
+ }) -> ( Hash[Symbol, ( String | Integer | bool )] | ::GraphQL::ExecutionError )
27
+
28
+ def self.argument: (*untyped) -> String
29
+ def self.type: (*untyped) -> String
30
+ end
31
+ end
32
+ TEXT
33
+ end
34
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
35
+ end
36
+ file_path
37
+ rescue Thor::Error => e
38
+ raise(Thor::Error, e)
39
+ end
40
+
41
+ def queries_rbs(class_name)
42
+ file_path = ""
43
+ Dir.chdir(Souls.get_mother_path.to_s) do
44
+ file_dir = "./sig/api/app/graphql/queries/"
45
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
46
+ pluralized_class_name = class_name.underscore.pluralize
47
+ file_path = "#{file_dir}#{pluralized_class_name}.rbs"
48
+ File.open(file_path, "w") do |f|
49
+ f.write(<<~TEXT)
50
+ module Queries
51
+ class BaseQuery
52
+ end
53
+ class #{pluralized_class_name.camelize} < Queries::BaseQuery
54
+ def resolve: () -> ( Hash[Symbol, ( String | Integer | bool )] | ::GraphQL::ExecutionError)
55
+ def self.type: (*untyped) -> String
56
+ end
57
+ end
58
+ TEXT
59
+ end
60
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
61
+ end
62
+ file_path
63
+ rescue Thor::Error => e
64
+ raise(Thor::Error, e)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,67 @@
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
+ params = Souls.get_relation_params(class_name: singularized_class_name)
14
+ File.open(file_path, "w") do |f|
15
+ f.write(<<~TEXT)
16
+ class Base
17
+ end
18
+ class #{singularized_class_name.camelize}Search < Base
19
+ def self.scope: () ?{ () -> nil } -> [Hash[Symbol, untyped]]
20
+ def self.type: (*untyped) -> String
21
+ def self.option: (:filter, type: untyped, with: :apply_filter) -> String
22
+ | (:first, type: untyped, with: :apply_first) -> String
23
+ | (:skip, type: untyped, with: :apply_skip) -> String
24
+ def self.description: (String) -> String
25
+ def self.types: (*untyped) -> String
26
+ def decode_global_key: (String value) -> Integer
27
+ def apply_filter: (untyped scope, untyped value) -> untyped
28
+ def normalize_filters: (untyped value, ?Array[untyped] branches) -> Array[untyped]
29
+
30
+ class #{singularized_class_name.camelize}Filter
31
+ String: String
32
+ Boolean: Boolean
33
+ Integer: Integer
34
+ TEXT
35
+ end
36
+ File.open(file_path, "a") do |f|
37
+ params[:params].each_with_index do |param, i|
38
+ type = Souls.rbs_type_check(param[:type])
39
+ type = "[#{type}]" if param[:array]
40
+ rbs_type = Souls.rbs_type_check(param[:type])
41
+ if i.zero?
42
+ f.write(" def self.argument: (:OR, [self], required: false) -> String\n")
43
+ else
44
+ f.write(" | (:#{param[:column_name]}, #{type}, required: false) -> #{rbs_type}\n")
45
+ end
46
+ end
47
+ end
48
+
49
+ File.open(file_path, "a") do |f|
50
+ f.write(<<~TEXT)
51
+ end
52
+ end
53
+ end
54
+ module Types
55
+ class BaseBaseInputObject
56
+ end
57
+ end
58
+ TEXT
59
+ end
60
+ end
61
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
62
+ file_path
63
+ rescue Thor::Error => e
64
+ raise(Thor::Error, e)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,50 @@
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.rbs_type_check(param[:type])
25
+ type = "[#{type}]" if param[:array]
26
+ rbs_type = Souls.rbs_type_check(param[:type])
27
+ if i.zero?
28
+ f.write(" def self.field: (:#{param[:column_name]}, #{type}, null: false) -> #{rbs_type}\n")
29
+ else
30
+ f.write(" | (:#{param[:column_name]}, #{type}, null: false) -> #{rbs_type}\n")
31
+ end
32
+ end
33
+ end
34
+
35
+ File.open(file_path, "a") do |f|
36
+ f.write(<<~TEXT)
37
+ def self.edge_type: () -> void
38
+ def self.connection_type: () -> void
39
+ end
40
+ end
41
+ TEXT
42
+ end
43
+ end
44
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
45
+ file_path
46
+ rescue Thor::Error => e
47
+ raise(Thor::Error, e)
48
+ end
49
+ end
50
+ end
data/lib/souls/cli.rb CHANGED
@@ -44,15 +44,17 @@ module Souls
44
44
  puts(Souls::VERSION)
45
45
  end
46
46
 
47
- desc "test", "Run (Rspec & steep check & Rubocop)"
47
+ desc "test", "Run Rspec & Rubocop"
48
48
  def test
49
49
  system("rubocop -A")
50
- system("steep check")
51
50
  system("bundle exec rspec")
52
51
  end
53
52
 
54
- desc "test_all", "Run Rspec & Rubocop"
53
+ desc "test_all", "Run (Rspec & steep check & Rubocop)"
55
54
  def test_all
55
+ Dir.chdir(Souls.get_mother_path.to_s) do
56
+ system("steep check")
57
+ end
56
58
  system("rubocop -A")
57
59
  system("bundle exec rspec")
58
60
  end
@@ -21,6 +21,19 @@ module Souls
21
21
  }[type.to_sym]
22
22
  end
23
23
 
24
+ def rbs_type_check(type)
25
+ {
26
+ bigint: "Integer",
27
+ string: "String",
28
+ float: "Float",
29
+ text: "String",
30
+ datetime: "String",
31
+ date: "String",
32
+ boolean: "bool",
33
+ integer: "Integer"
34
+ }[type.to_sym]
35
+ end
36
+
24
37
  def get_type_and_name(line)
25
38
  line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
26
39
  end
@@ -98,13 +111,30 @@ module Souls
98
111
  end
99
112
  end
100
113
 
114
+ def get_relation_params(class_name: "user", col: "")
115
+ cols =
116
+ if col == "mutation"
117
+ get_columns_num_no_timestamp(class_name: class_name)
118
+ else
119
+ get_columns_num(class_name: class_name)
120
+ end
121
+ relation_params = cols.select { |col| col[:column_name].match?(/_id$/) }
122
+ user_check =
123
+ relation_params.map do |param|
124
+ param[:column_name] == "user_id"
125
+ end
126
+ user_exist = user_check.include?(true)
127
+ { user_exist: user_exist, params: cols, relation_params: relation_params }
128
+ end
129
+
101
130
  def get_columns_num(class_name: "user")
131
+ pluralized_class_name = class_name.pluralize
102
132
  file_path = "./db/schema.rb"
103
133
  class_check_flag = false
104
134
  cols = []
105
135
  File.open(file_path, "r") do |f|
106
136
  f.each_line.with_index do |line, _i|
107
- class_check_flag = true if line.include?("create_table") && line.include?(class_name)
137
+ class_check_flag = true if line.include?("create_table") && line.include?(pluralized_class_name)
108
138
  if class_check_flag == true && !line.include?("create_table")
109
139
  return cols if line.include?("t.index") || line.strip == "end"
110
140
 
@@ -117,6 +147,29 @@ module Souls
117
147
  cols
118
148
  end
119
149
 
150
+ def get_columns_num_no_timestamp(class_name: "user")
151
+ pluralized_class_name = class_name.pluralize
152
+ file_path = "./db/schema.rb"
153
+ class_check_flag = false
154
+ cols = []
155
+ File.open(file_path, "r") do |f|
156
+ f.each_line.with_index do |line, _i|
157
+ class_check_flag = true if line.include?("create_table") && line.include?(pluralized_class_name)
158
+ if class_check_flag == true && !line.include?("create_table")
159
+ return cols if line.include?("t.index") || line.strip == "end"
160
+
161
+ types = Souls.get_type_and_name(line)
162
+ array = line.include?("array: true")
163
+ cols << { column_name: types[1], type: types[0], array: array } unless %w[
164
+ created_at
165
+ updated_at
166
+ ].include?(types[1])
167
+ end
168
+ end
169
+ end
170
+ cols
171
+ end
172
+
120
173
  def get_create_migration_type(class_name: "user")
121
174
  pluralized_class_name = class_name.pluralize
122
175
  file_path = Dir["db/migrate/*_create_#{pluralized_class_name}.rb"][0]
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.55.2".freeze
2
+ VERSION = "0.56.0".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.34.2
1
+ 0.35.0
@@ -1 +1 @@
1
- 0.34.2
1
+ 0.35.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.55.2
4
+ version: 0.56.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -131,13 +131,19 @@ files:
131
131
  - lib/souls/api/generate/connection.rb
132
132
  - lib/souls/api/generate/connection_rbs.rb
133
133
  - lib/souls/api/generate/edge.rb
134
+ - lib/souls/api/generate/edge_rbs.rb
134
135
  - lib/souls/api/generate/index.rb
135
136
  - lib/souls/api/generate/manager.rb
136
137
  - lib/souls/api/generate/model.rb
138
+ - lib/souls/api/generate/model_rbs.rb
137
139
  - lib/souls/api/generate/mutation.rb
140
+ - lib/souls/api/generate/mutation_rbs.rb
138
141
  - lib/souls/api/generate/policy.rb
142
+ - lib/souls/api/generate/policy_rbs.rb
139
143
  - lib/souls/api/generate/query.rb
144
+ - lib/souls/api/generate/query_rbs.rb
140
145
  - lib/souls/api/generate/resolver.rb
146
+ - lib/souls/api/generate/resolver_rbs.rb
141
147
  - lib/souls/api/generate/rspec_factory.rb
142
148
  - lib/souls/api/generate/rspec_model.rb
143
149
  - lib/souls/api/generate/rspec_mutation.rb
@@ -145,6 +151,7 @@ files:
145
151
  - lib/souls/api/generate/rspec_query.rb
146
152
  - lib/souls/api/generate/rspec_resolver.rb
147
153
  - lib/souls/api/generate/type.rb
154
+ - lib/souls/api/generate/type_rbs.rb
148
155
  - lib/souls/api/index.rb
149
156
  - lib/souls/api/update/index.rb
150
157
  - lib/souls/api/update/mutation.rb