souls 0.64.3 → 0.65.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3a33999e189283758881dbe8f9d0a7222580ca0b359363d845142aecc6faf63
4
- data.tar.gz: addf19b1163e5ae31937b0fe49ce464ed4de286d1edc013385a968dd721f858d
3
+ metadata.gz: f067eba7f9bf393c19177e68748534be2a5a728543fa5962dc4e5bc11a8d89f4
4
+ data.tar.gz: 6f954ae664e35fe87252152d75c91ae13aa2da150ee5447c072b43cc8426c5c4
5
5
  SHA512:
6
- metadata.gz: f19ae2ed49b96c8ac03e5944c79ac9f0cd8da0a4e7875660c83236c0cc645c16f064c4f97fa53d1b7c9ee3ae61ad9648c1cd3a4f84c038034ed57743cca7edc2
7
- data.tar.gz: e95ee79d899afb8a255018c6d0da216e400f0689690cb2d1cc4a83f30c644ee7f2d7d35597f17a0ab07db1e887b1e0b29e7d786c51ab6d620351384f07b65d8d
6
+ metadata.gz: 72b65bc98b779719626ff4b95890da9ec4e0740a1eccb981c95de7346934c7e73a813e4ceaefec947c9d2b82fcd17a2e08ad09d111acbf4fe975831441be92e7
7
+ data.tar.gz: f341b2cba0d2223038a60be61c393e3ba5ce779947e1f0d1ad7aa065adac38c33139dc14f86d622649535033c96b9c00bea4950a19ab6fe210585355b481e483
@@ -45,6 +45,8 @@ module Souls
45
45
  type = Souls.type_check(param[:type])
46
46
  type = "[#{type}]" if param[:array]
47
47
  type = "String" if param[:column_name].match?(/$*_id\z/)
48
+ next if params[:column_name] == "user_id"
49
+
48
50
  if i == params[:params].size - 1
49
51
  f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
50
52
  f.write(" def resolve(args)\n")
@@ -89,94 +91,67 @@ module Souls
89
91
  file_path
90
92
  end
91
93
 
92
- ## 2.Mutation - Update
93
- def update_mutation_head(class_name: "user")
94
+ def update_mutation(class_name: "user")
94
95
  singularized_class_name = class_name.singularize.underscore
95
96
  file_dir = "./app/graphql/mutations/base/#{singularized_class_name}"
96
- file_path = "#{file_dir}/update_#{class_name}.rb"
97
- File.open(file_path, "w") do |new_line|
98
- new_line.write(<<~TEXT)
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)
99
104
  module Mutations
100
- module Base::#{class_name.camelize}
101
- class Update#{class_name.camelize} < BaseMutation
102
- field :#{class_name}_edge, Types::#{class_name.camelize}Type.edge_type, null: false
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
103
109
 
104
110
  argument :id, String, required: true
105
111
  TEXT
106
112
  end
107
- file_path
108
- end
109
-
110
- def update_mutation_params(class_name: "user")
111
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
112
- path = "./db/schema.rb"
113
- @on = false
114
- @user_exist = false
115
- @relation_params = []
116
- File.open(file_path, "a") do |new_line|
117
- File.open(path, "r") do |f|
118
- f.each_line.with_index do |line, _i|
119
- if @on
120
- if line.include?("t.index") || line.strip == "end"
121
- if @user_exist
122
- new_line.write(<<-TEXT)
123
113
 
124
- def resolve args
125
- params = args.dup
126
- params[:user_id] = context[:user][:id]
127
- _, params[:id] = SoulsApiSchema.from_global_id(args[:id])
128
- TEXT
129
- else
130
- 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"
131
120
 
132
- def resolve args
133
- params = args.dup
134
- _, params[:id] = SoulsApiSchema.from_global_id(args[:id])
135
- TEXT
136
- end
137
- break
138
- end
139
- field = "[String]" if line.include?("array: true")
140
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
141
- field ||= Souls.type_check(type)
142
- case name
143
- when "user_id"
144
- @user_exist = true
145
- when /$*_id\z/
146
- @relation_params << name
147
- new_line.write(" argument :#{name}, String, required: false\n")
148
- when "created_at", "updated_at"
149
- next
150
- else
151
- new_line.write(" argument :#{name}, #{field}, required: false\n")
152
- end
153
- end
154
- @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")
155
126
  end
156
127
  end
157
128
  end
158
- @relation_params
159
- end
160
129
 
161
- def update_mutation_after_params(class_name: "article", relation_params: [])
162
- return false if relation_params.empty?
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"
163
135
 
164
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
165
- relation_params.each do |params_name|
166
- File.open(file_path, "a") do |new_line|
167
- new_line.write(" _, params[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
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")
168
148
  end
169
149
  end
170
- true
171
- end
172
-
173
- def update_mutation_end(class_name: "user")
174
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
175
150
  File.open(file_path, "a") do |new_line|
176
151
  new_line.write(<<~TEXT)
177
- #{class_name} = ::#{class_name.camelize}.find params[:id]
178
- #{class_name}.update params
179
- { #{class_name}_edge: { node: ::#{class_name.camelize}.find(params[:id]) } }
152
+ raise(StandardError, data.errors.full_messages) unless data.save
153
+
154
+ { #{singularized_class_name}_edge: { node: data } }
180
155
  rescue StandardError => error
181
156
  GraphQL::ExecutionError.new(error.message)
182
157
  end
@@ -189,16 +164,6 @@ module Souls
189
164
  file_path
190
165
  end
191
166
 
192
- def update_mutation(class_name: "user")
193
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
194
- return "Mutation already exist! #{file_path}" if File.exist?(file_path)
195
-
196
- update_mutation_head(class_name: class_name)
197
- relation_params = update_mutation_params(class_name: class_name)
198
- update_mutation_after_params(class_name: class_name, relation_params: relation_params)
199
- update_mutation_end(class_name: class_name)
200
- end
201
-
202
167
  # 3. Mutation - Delete
203
168
  def delete_mutation(class_name: "user")
204
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
- f.write(" def self.field: (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
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")
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,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.64.3".freeze
2
+ VERSION = "0.65.3".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.43.3
1
+ 0.44.3
@@ -1 +1 @@
1
- 0.43.3
1
+ 0.44.3
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.64.3
4
+ version: 0.65.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI