souls 0.64.1 → 0.65.1
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 +46 -85
- data/lib/souls/cli/generate/mutation_rbs.rb +4 -0
- data/lib/souls/cli/generate/type_rbs.rb +3 -0
- 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: 8f8176d143c89bdaa40a3a3526d94eae4ec4c5d690e8e6284388a0aceb568a40
|
4
|
+
data.tar.gz: 5e1fd6e6dbb61780bdde190dc69ef6f577450dddc9bbf9a3b3f11049622969e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd18ce063b90f06cb385c2fa5da8fb9b1fcc64908f6ad5aa8831238bd6fcb2f14cb0f56fa03003ad2756067efdf6ed5e4be3dcdf9c5e481eb6a6d4eb3b870867
|
7
|
+
data.tar.gz: df23195180ebb2b4ce50018f7662dc400ad328eb741788e3a80461f4e44149c66258530ae093e602ac9d666f6e2a09bc66023239a1f509ae55e34719ad717c5a
|
@@ -44,11 +44,12 @@ 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/)
|
47
48
|
if i == params[:params].size - 1
|
48
|
-
f.write(" argument :#{param[:column_name]}, #{type},
|
49
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
|
49
50
|
f.write(" def resolve(args)\n")
|
50
51
|
else
|
51
|
-
f.write(" argument :#{param[:column_name]}, #{type},
|
52
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n")
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -59,7 +60,7 @@ module Souls
|
|
59
60
|
params[:relation_params].each_with_index do |col, _i|
|
60
61
|
next if col[:column_name] == "user_id"
|
61
62
|
|
62
|
-
f.write("
|
63
|
+
f.write(" _, #{col[:column_name]} = SoulsApiSchema.from_global_id(args[:#{col[:column_name]}])\n")
|
63
64
|
end
|
64
65
|
relation_params =
|
65
66
|
params[:relation_params].map do |n|
|
@@ -88,94 +89,64 @@ module Souls
|
|
88
89
|
file_path
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
-
def update_mutation_head(class_name: "user")
|
92
|
+
def update_mutation(class_name: "user")
|
93
93
|
singularized_class_name = class_name.singularize.underscore
|
94
94
|
file_dir = "./app/graphql/mutations/base/#{singularized_class_name}"
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
96
|
+
file_path = "#{file_dir}/update_#{singularized_class_name}.rb"
|
97
|
+
raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
|
98
|
+
|
99
|
+
params = Souls.get_relation_params(class_name: singularized_class_name, col: "mutation")
|
100
|
+
File.open(file_path, "w") do |f|
|
101
|
+
f.write(<<~TEXT)
|
98
102
|
module Mutations
|
99
|
-
module Base::#{
|
100
|
-
class Update#{
|
101
|
-
field :#{
|
103
|
+
module Base::#{singularized_class_name.camelize}
|
104
|
+
class Update#{singularized_class_name.camelize} < BaseMutation
|
105
|
+
field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}Type.edge_type, null: false
|
106
|
+
field :error, String, null: true
|
102
107
|
|
103
|
-
argument :id, String, required: true
|
104
108
|
TEXT
|
105
109
|
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
110
|
|
123
|
-
|
124
|
-
params
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
_, params[:id] = SoulsApiSchema.from_global_id(args[:id])
|
134
|
-
TEXT
|
135
|
-
end
|
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)
|
111
|
+
File.open(file_path, "a") do |f|
|
112
|
+
params[:params].each_with_index do |param, i|
|
113
|
+
type = Souls.type_check(param[:type])
|
114
|
+
type = "[#{type}]" if param[:array]
|
115
|
+
type = "String" if param[:column_name].match?(/$*_id\z/)
|
116
|
+
if i == params[:params].size - 1
|
117
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
|
118
|
+
f.write(" def resolve(args)\n")
|
119
|
+
else
|
120
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n")
|
154
121
|
end
|
155
122
|
end
|
156
123
|
end
|
157
|
-
@relation_params
|
158
|
-
end
|
159
124
|
|
160
|
-
|
161
|
-
|
125
|
+
File.open(file_path, "a") do |f|
|
126
|
+
if params[:relation_params]
|
127
|
+
f.write(" user_id = context[:user][:id]\n") if params[:user_exist]
|
128
|
+
params[:relation_params].each_with_index do |col, _i|
|
129
|
+
next if col[:column_name] == "user_id"
|
162
130
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
131
|
+
f.write(" _, #{col[:column_name]} = SoulsApiSchema.from_global_id(args[:#{col[:column_name]}])\n")
|
132
|
+
end
|
133
|
+
relation_params =
|
134
|
+
params[:relation_params].map do |n|
|
135
|
+
", #{n[:column_name]}: #{n[:column_name]}"
|
136
|
+
end
|
137
|
+
f.write(" new_record = { **args #{relation_params.compact.join} }\n")
|
138
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(article_id)\n")
|
139
|
+
f.write(" data.update(new_record)\n")
|
140
|
+
else
|
141
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(article_id)\n")
|
142
|
+
f.write(" data.update(args)\n")
|
167
143
|
end
|
168
144
|
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
145
|
File.open(file_path, "a") do |new_line|
|
175
146
|
new_line.write(<<~TEXT)
|
176
|
-
|
177
|
-
|
178
|
-
{ #{
|
147
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
148
|
+
|
149
|
+
{ #{singularized_class_name}_edge: { node: data } }
|
179
150
|
rescue StandardError => error
|
180
151
|
GraphQL::ExecutionError.new(error.message)
|
181
152
|
end
|
@@ -188,16 +159,6 @@ module Souls
|
|
188
159
|
file_path
|
189
160
|
end
|
190
161
|
|
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
162
|
# 3. Mutation - Delete
|
202
163
|
def delete_mutation(class_name: "user")
|
203
164
|
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
|
@@ -26,6 +26,9 @@ module Souls
|
|
26
26
|
rbs_type = Souls.rbs_type_check(param[:type])
|
27
27
|
if i.zero?
|
28
28
|
f.write(" def self.field: (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
|
29
|
+
elsif param[:column_name].match?(/$*_id\z/)
|
30
|
+
col_name = param[:column_name].gsub("_id", "")
|
31
|
+
f.write(" | (:#{col_name}, untyped, null: false) -> untyped\n")
|
29
32
|
else
|
30
33
|
f.write(" | (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
|
31
34
|
end
|
data/lib/souls/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.1
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.1
|