souls 0.64.2 → 0.65.2
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 +4 -4
- data/lib/souls/cli/generate/mutation.rb +47 -81
- data/lib/souls/cli/generate/mutation_rbs.rb +4 -0
- data/lib/souls/cli/generate/type_rbs.rb +9 -1
- data/lib/souls/version.rb +1 -1
- data/lib/souls/versions/.souls_api_version +1 -1
- data/lib/souls/versions/.souls_worker_version +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823211ff017cc0697fcc8934588a99c7a57944c926ec55a792a805253d8bb69b
|
4
|
+
data.tar.gz: 3c0a44c8218f52c427762f82e9cf7d15acf16223e99d31e6e9d410b93375465c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e65fb7ad445b4eca17874fe5bd64dc70b64d42762811983869cc372d69a14670fcd706a88f08305f337caf5d54018f3a588ce2663df7c4b5b8d5692221c2cb91
|
7
|
+
data.tar.gz: aaa7277667d84c1798ca10511045f4086db1834b983660bae67138dfebef1dadb6736a6094d019bd0aa48752b9fbb224bb3f569995fc0f9d7b39dc38d942e2f1
|
@@ -44,6 +44,9 @@ module Souls
|
|
44
44
|
params[:params].each_with_index do |param, i|
|
45
45
|
type = Souls.type_check(param[:type])
|
46
46
|
type = "[#{type}]" if param[:array]
|
47
|
+
type = "String" if param[:column_name].match?(/$*_id\z/)
|
48
|
+
next if params[:column_name] == "user_id"
|
49
|
+
|
47
50
|
if i == params[:params].size - 1
|
48
51
|
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
|
49
52
|
f.write(" def resolve(args)\n")
|
@@ -59,7 +62,7 @@ module Souls
|
|
59
62
|
params[:relation_params].each_with_index do |col, _i|
|
60
63
|
next if col[:column_name] == "user_id"
|
61
64
|
|
62
|
-
f.write("
|
65
|
+
f.write(" _, #{col[:column_name]} = SoulsApiSchema.from_global_id(args[:#{col[:column_name]}])\n")
|
63
66
|
end
|
64
67
|
relation_params =
|
65
68
|
params[:relation_params].map do |n|
|
@@ -88,94 +91,67 @@ module Souls
|
|
88
91
|
file_path
|
89
92
|
end
|
90
93
|
|
91
|
-
|
92
|
-
def update_mutation_head(class_name: "user")
|
94
|
+
def update_mutation(class_name: "user")
|
93
95
|
singularized_class_name = class_name.singularize.underscore
|
94
96
|
file_dir = "./app/graphql/mutations/base/#{singularized_class_name}"
|
95
|
-
|
96
|
-
|
97
|
-
|
97
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
98
|
+
file_path = "#{file_dir}/update_#{singularized_class_name}.rb"
|
99
|
+
raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
|
100
|
+
|
101
|
+
params = Souls.get_relation_params(class_name: singularized_class_name, col: "mutation")
|
102
|
+
File.open(file_path, "w") do |f|
|
103
|
+
f.write(<<~TEXT)
|
98
104
|
module Mutations
|
99
|
-
module Base::#{
|
100
|
-
class Update#{
|
101
|
-
field :#{
|
105
|
+
module Base::#{singularized_class_name.camelize}
|
106
|
+
class Update#{singularized_class_name.camelize} < BaseMutation
|
107
|
+
field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}Type.edge_type, null: false
|
108
|
+
field :error, String, null: true
|
102
109
|
|
103
110
|
argument :id, String, required: true
|
104
111
|
TEXT
|
105
112
|
end
|
106
|
-
file_path
|
107
|
-
end
|
108
|
-
|
109
|
-
def update_mutation_params(class_name: "user")
|
110
|
-
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
111
|
-
path = "./db/schema.rb"
|
112
|
-
@on = false
|
113
|
-
@user_exist = false
|
114
|
-
@relation_params = []
|
115
|
-
File.open(file_path, "a") do |new_line|
|
116
|
-
File.open(path, "r") do |f|
|
117
|
-
f.each_line.with_index do |line, _i|
|
118
|
-
if @on
|
119
|
-
if line.include?("t.index") || line.strip == "end"
|
120
|
-
if @user_exist
|
121
|
-
new_line.write(<<-TEXT)
|
122
113
|
|
123
|
-
|
124
|
-
params
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
new_line.write(<<-TEXT)
|
114
|
+
File.open(file_path, "a") do |f|
|
115
|
+
params[:params].each_with_index do |param, i|
|
116
|
+
type = Souls.type_check(param[:type])
|
117
|
+
type = "[#{type}]" if param[:array]
|
118
|
+
type = "String" if param[:column_name].match?(/$*_id\z/)
|
119
|
+
next if col[:column_name] == "user_id"
|
130
120
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
break
|
137
|
-
end
|
138
|
-
field = "[String]" if line.include?("array: true")
|
139
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
140
|
-
field ||= Souls.type_check(type)
|
141
|
-
case name
|
142
|
-
when "user_id"
|
143
|
-
@user_exist = true
|
144
|
-
when /$*_id\z/
|
145
|
-
@relation_params << name
|
146
|
-
new_line.write(" argument :#{name}, String, required: false\n")
|
147
|
-
when "created_at", "updated_at"
|
148
|
-
next
|
149
|
-
else
|
150
|
-
new_line.write(" argument :#{name}, #{field}, required: false\n")
|
151
|
-
end
|
152
|
-
end
|
153
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
121
|
+
if i == params[:params].size - 1
|
122
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
|
123
|
+
f.write(" def resolve(args)\n")
|
124
|
+
else
|
125
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n")
|
154
126
|
end
|
155
127
|
end
|
156
128
|
end
|
157
|
-
@relation_params
|
158
|
-
end
|
159
129
|
|
160
|
-
|
161
|
-
|
130
|
+
File.open(file_path, "a") do |f|
|
131
|
+
if params[:relation_params]
|
132
|
+
f.write(" user_id = context[:user][:id]\n") if params[:user_exist]
|
133
|
+
params[:relation_params].each_with_index do |col, _i|
|
134
|
+
next if col[:column_name] == "user_id"
|
162
135
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
136
|
+
f.write(" _, #{col[:column_name]} = SoulsApiSchema.from_global_id(args[:#{col[:column_name]}])\n")
|
137
|
+
end
|
138
|
+
relation_params =
|
139
|
+
params[:relation_params].map do |n|
|
140
|
+
", #{n[:column_name]}: #{n[:column_name]}"
|
141
|
+
end
|
142
|
+
f.write(" new_record = { **args #{relation_params.compact.join} }\n")
|
143
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(article_id)\n")
|
144
|
+
f.write(" data.update(new_record)\n")
|
145
|
+
else
|
146
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(args[:id])\n")
|
147
|
+
f.write(" data.update(args)\n")
|
167
148
|
end
|
168
149
|
end
|
169
|
-
true
|
170
|
-
end
|
171
|
-
|
172
|
-
def update_mutation_end(class_name: "user")
|
173
|
-
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
174
150
|
File.open(file_path, "a") do |new_line|
|
175
151
|
new_line.write(<<~TEXT)
|
176
|
-
|
177
|
-
|
178
|
-
{ #{
|
152
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
153
|
+
|
154
|
+
{ #{singularized_class_name}_edge: { node: data } }
|
179
155
|
rescue StandardError => error
|
180
156
|
GraphQL::ExecutionError.new(error.message)
|
181
157
|
end
|
@@ -188,16 +164,6 @@ module Souls
|
|
188
164
|
file_path
|
189
165
|
end
|
190
166
|
|
191
|
-
def update_mutation(class_name: "user")
|
192
|
-
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
193
|
-
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
194
|
-
|
195
|
-
update_mutation_head(class_name: class_name)
|
196
|
-
relation_params = update_mutation_params(class_name: class_name)
|
197
|
-
update_mutation_after_params(class_name: class_name, relation_params: relation_params)
|
198
|
-
update_mutation_end(class_name: class_name)
|
199
|
-
end
|
200
|
-
|
201
167
|
# 3. Mutation - Delete
|
202
168
|
def delete_mutation(class_name: "user")
|
203
169
|
file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
|
@@ -42,6 +42,8 @@ module Souls
|
|
42
42
|
type = "[#{type}]" if param[:array]
|
43
43
|
if i == params[:params].size - 1
|
44
44
|
f.write(" #{param[:column_name]}: #{type}?\n")
|
45
|
+
elsif param[:column_name].match?(/$*_id\z/)
|
46
|
+
f.write(" #{param[:column_name]}: String?,\n")
|
45
47
|
else
|
46
48
|
f.write(" #{param[:column_name]}: #{type}?,\n")
|
47
49
|
end
|
@@ -60,6 +62,8 @@ module Souls
|
|
60
62
|
type = "[#{type}]" if param[:array]
|
61
63
|
if i.zero?
|
62
64
|
f.write(" def self.argument: (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
|
65
|
+
elsif param[:column_name].match?(/$*_id\z/)
|
66
|
+
f.write(" | (:#{param[:column_name]}, String, required: false ) -> String\n")
|
63
67
|
else
|
64
68
|
f.write(" | (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
|
65
69
|
end
|
@@ -25,7 +25,15 @@ module Souls
|
|
25
25
|
type = "[#{type}]" if param[:array]
|
26
26
|
rbs_type = Souls.rbs_type_check(param[:type])
|
27
27
|
if i.zero?
|
28
|
-
|
28
|
+
if params[: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")
|
29
37
|
else
|
30
38
|
f.write(" | (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
|
31
39
|
end
|
data/lib/souls/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.2
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.2
|