souls 0.44.5 → 0.45.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/README.md +5 -2
- data/exe/souls +9 -1
- data/lib/souls/api/generate/application.rb +145 -143
- data/lib/souls/api/generate/connection.rb +1 -1
- data/lib/souls/api/generate/edge.rb +1 -1
- data/lib/souls/api/generate/model.rb +1 -1
- data/lib/souls/api/generate/mutation.rb +221 -219
- data/lib/souls/api/generate/policy.rb +1 -1
- data/lib/souls/api/generate/query.rb +49 -47
- data/lib/souls/api/generate/resolver.rb +123 -121
- data/lib/souls/api/generate/rspec_factory.rb +49 -47
- data/lib/souls/api/generate/rspec_model.rb +1 -1
- data/lib/souls/api/generate/rspec_mutation.rb +215 -213
- data/lib/souls/api/generate/rspec_policy.rb +1 -1
- data/lib/souls/api/generate/rspec_query.rb +134 -132
- data/lib/souls/api/generate/rspec_resolver.rb +159 -157
- data/lib/souls/api/generate/type.rb +4 -4
- data/lib/souls/cli/gcloud/sql/index.rb +11 -5
- 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
- data/lib/souls/worker/generate/mailer.rb +1 -0
- data/lib/souls/worker/generate/mutation.rb +11 -2
- metadata +1 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Policy
|
4
|
-
def self.policy(class_name: "
|
4
|
+
def self.policy(class_name: "user")
|
5
5
|
dir_name = "./app/policies"
|
6
6
|
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
7
7
|
file_path = "#{dir_name}/#{class_name.singularize}_policy.rb"
|
@@ -1,66 +1,68 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Query / Queries
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
class << self
|
5
|
+
def create_queries(class_name: "user")
|
6
|
+
file_path = "./app/graphql/queries/#{class_name.pluralize}.rb"
|
7
|
+
return "Query already exist! #{file_path}" if File.exist?(file_path)
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
File.open(file_path, "w") do |f|
|
10
|
+
f.write(<<~TEXT)
|
11
|
+
module Queries
|
12
|
+
class #{class_name.camelize.pluralize} < Queries::BaseQuery
|
13
|
+
type [Types::#{class_name.camelize}Type], null: false
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def resolve
|
16
|
+
::#{class_name.camelize}.all
|
17
|
+
rescue StandardError => error
|
18
|
+
GraphQL::ExecutionError.new error
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
|
-
|
21
|
-
|
22
|
+
TEXT
|
23
|
+
end
|
24
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
25
|
+
file_path
|
26
|
+
rescue StandardError => e
|
27
|
+
raise(StandardError, e)
|
22
28
|
end
|
23
|
-
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
24
|
-
file_path
|
25
|
-
rescue StandardError => e
|
26
|
-
raise(StandardError, e)
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def create_query(class_name: "user")
|
31
|
+
file_path = "./app/graphql/queries/#{class_name}.rb"
|
32
|
+
return "Query already exist! #{file_path}" if File.exist?(file_path)
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
File.open(file_path, "w") do |f|
|
35
|
+
f.write(<<~TEXT)
|
36
|
+
module Queries
|
37
|
+
class #{class_name.camelize} < Queries::BaseQuery
|
38
|
+
type Types::#{class_name.camelize}Type, null: false
|
39
|
+
argument :id, String, required: true
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def resolve **args
|
42
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
43
|
+
::#{class_name.camelize}.find(data_id)
|
44
|
+
rescue StandardError => error
|
45
|
+
GraphQL::ExecutionError.new error
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
TEXT
|
50
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
51
|
+
file_path
|
52
|
+
rescue StandardError => e
|
53
|
+
raise(StandardError, e)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def query(class_name: "user")
|
58
|
+
file_dir = "./app/graphql/queries/"
|
59
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
60
|
+
singularized_class_name = class_name.singularize
|
61
|
+
create_query(class_name: singularized_class_name)
|
62
|
+
create_queries(class_name: singularized_class_name)
|
51
63
|
rescue StandardError => e
|
52
64
|
raise(StandardError, e)
|
53
65
|
end
|
54
66
|
end
|
55
|
-
|
56
|
-
def self.query(class_name: "souls")
|
57
|
-
file_dir = "./app/graphql/queries/"
|
58
|
-
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
59
|
-
singularized_class_name = class_name.singularize
|
60
|
-
create_query(class_name: singularized_class_name)
|
61
|
-
create_queries(class_name: singularized_class_name)
|
62
|
-
rescue StandardError => e
|
63
|
-
raise(StandardError, e)
|
64
|
-
end
|
65
67
|
end
|
66
68
|
end
|
@@ -1,156 +1,158 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Resolver
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
class << self
|
5
|
+
def resolver_head(class_name: "user")
|
6
|
+
FileUtils.mkdir_p("./app/graphql/resolvers") unless Dir.exist?("./app/graphql/resolvers")
|
7
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
8
|
+
@relation_params = []
|
9
|
+
File.open(file_path, "w") do |f|
|
10
|
+
f.write(<<~TEXT)
|
11
|
+
module Resolvers
|
12
|
+
class #{class_name.camelize}Search < Base
|
13
|
+
include SearchObject.module(:graphql)
|
14
|
+
scope { ::#{class_name.camelize}.all }
|
15
|
+
type Types::#{class_name.camelize}Type.connection_type, null: false
|
16
|
+
description "Search #{class_name.camelize}"
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
class #{class_name.camelize}Filter < ::Types::BaseInputObject
|
19
|
+
argument :OR, [self], required: false
|
20
|
+
TEXT
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
def resolver_params(class_name: "user")
|
25
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
26
|
+
path = "./db/schema.rb"
|
27
|
+
@on = false
|
28
|
+
@user_exist = false
|
29
|
+
@relation_params = []
|
30
|
+
File.open(file_path, "a") do |new_line|
|
31
|
+
File.open(path, "r") do |f|
|
32
|
+
f.each_line.with_index do |line, _i|
|
33
|
+
if @on
|
34
|
+
break if line.include?("t.index") || line.strip == "end"
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
36
|
+
field = "[String]" if line.include?("array: true")
|
37
|
+
type, name = get_type_and_name(line)
|
38
|
+
field ||= type_check(type)
|
39
|
+
case name
|
40
|
+
when "user_id"
|
41
|
+
@user_exist = true
|
42
|
+
when /$*_id\z/
|
43
|
+
@relation_params << name
|
44
|
+
new_line.write(" argument :#{name}, String, required: false\n")
|
45
|
+
when "created_at", "updated_at"
|
46
|
+
next
|
47
|
+
else
|
48
|
+
new_line.write(" argument :#{name}, #{field}, required: false\n")
|
49
|
+
end
|
48
50
|
end
|
51
|
+
@on = true if table_check(line: line, class_name: class_name)
|
49
52
|
end
|
50
|
-
@on = true if table_check(line: line, class_name: class_name)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
def resolver_after_params(class_name: "user")
|
58
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
59
|
+
File.open(file_path, "a") do |f|
|
60
|
+
f.write(<<-TEXT)
|
61
|
+
argument :start_date, String, required: false
|
62
|
+
argument :end_date, String, required: false
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
|
66
|
+
option :first, type: types.Int, with: :apply_first
|
67
|
+
option :skip, type: types.Int, with: :apply_skip
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
def apply_filter(scope, value)
|
70
|
+
branches = normalize_filters(value).inject { |a, b| a.or(b) }
|
71
|
+
scope.merge branches
|
72
|
+
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
def normalize_filters(value, branches = [])
|
75
|
+
scope = ::#{class_name.camelize}.all
|
76
|
+
TEXT
|
77
|
+
end
|
76
78
|
end
|
77
|
-
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
80
|
+
def resolver_before_end(class_name: "user")
|
81
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
82
|
+
path = "./db/schema.rb"
|
83
|
+
@on = false
|
84
|
+
@user_exist = false
|
85
|
+
@relation_params = []
|
86
|
+
File.open(file_path, "a") do |new_line|
|
87
|
+
File.open(path, "r") do |f|
|
88
|
+
f.each_line.with_index do |line, _i|
|
89
|
+
if @on
|
90
|
+
break if line.include?("t.index") || line.strip == "end"
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
else
|
109
|
-
case type
|
110
|
-
when "boolean"
|
111
|
-
new_line.write(" scope = scope.where(#{name}: value[:#{name}]) unless value[:#{name}].nil?\n")
|
92
|
+
type, name = get_type_and_name(line)
|
93
|
+
if line.include?("array: true")
|
94
|
+
new_line.write(
|
95
|
+
" scope = scope.where(\"#{name} @> ARRAY[?]::text[]\", value[:#{name}]) if value[:#{name}]\n"
|
96
|
+
)
|
97
|
+
next
|
98
|
+
end
|
99
|
+
case name
|
100
|
+
when "user_id"
|
101
|
+
@user_exist = true
|
102
|
+
when /$*_id\z/
|
103
|
+
@relation_params << name
|
104
|
+
new_line.write(
|
105
|
+
" scope = scope.where(#{name}: decode_global_key(value[:#{name}])) if value[:#{name}]\n"
|
106
|
+
)
|
107
|
+
when "created_at", "updated_at"
|
108
|
+
next
|
112
109
|
else
|
113
|
-
|
110
|
+
case type
|
111
|
+
when "boolean"
|
112
|
+
new_line.write(" scope = scope.where(#{name}: value[:#{name}]) unless value[:#{name}].nil?\n")
|
113
|
+
else
|
114
|
+
new_line.write(" scope = scope.where(#{name}: value[:#{name}]) if value[:#{name}]\n")
|
115
|
+
end
|
114
116
|
end
|
115
117
|
end
|
118
|
+
@on = true if table_check(line: line, class_name: class_name)
|
116
119
|
end
|
117
|
-
@on = true if table_check(line: line, class_name: class_name)
|
118
120
|
end
|
119
121
|
end
|
120
122
|
end
|
121
|
-
end
|
122
123
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
124
|
+
def resolver_end(class_name: "user")
|
125
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
126
|
+
File.open(file_path, "a") do |f|
|
127
|
+
f.write(<<~TEXT)
|
128
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
129
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
130
|
+
branches << scope
|
131
|
+
value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
|
132
|
+
branches
|
133
|
+
end
|
132
134
|
end
|
133
135
|
end
|
134
|
-
|
135
|
-
|
136
|
+
TEXT
|
137
|
+
end
|
138
|
+
file_path
|
136
139
|
end
|
137
|
-
file_path
|
138
|
-
end
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
def resolver(class_name: "user")
|
142
|
+
singularized_class_name = class_name.singularize.underscore
|
143
|
+
file_path = "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
|
144
|
+
raise(StandardError, "Resolver already exist! #{file_path}") if File.exist?(file_path)
|
144
145
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
146
|
+
resolver_head(class_name: singularized_class_name)
|
147
|
+
resolver_params(class_name: singularized_class_name)
|
148
|
+
resolver_after_params(class_name: singularized_class_name)
|
149
|
+
resolver_before_end(class_name: singularized_class_name)
|
150
|
+
resolver_end(class_name: singularized_class_name)
|
151
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
152
|
+
file_path
|
153
|
+
rescue StandardError => e
|
154
|
+
raise(StandardError, e)
|
155
|
+
end
|
154
156
|
end
|
155
157
|
end
|
156
158
|
end
|
@@ -1,65 +1,67 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Rspec Factory
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
class << self
|
5
|
+
def rspec_factory_head(class_name: "user")
|
6
|
+
file_path = "./spec/factories/#{class_name.pluralize}.rb"
|
7
|
+
FileUtils.mkdir_p("./spec/factories/") unless Dir.exist?("./spec/factories/")
|
8
|
+
File.open(file_path, "w") do |f|
|
9
|
+
f.write(<<~TEXT)
|
10
|
+
FactoryBot.define do
|
11
|
+
factory :#{class_name} do
|
12
|
+
TEXT
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
16
|
+
def rspec_factory_params(class_name: "user")
|
17
|
+
file_path = "./spec/factories/#{class_name.pluralize}.rb"
|
18
|
+
path = "./db/schema.rb"
|
19
|
+
@on = false
|
20
|
+
File.open(file_path, "a") do |new_line|
|
21
|
+
File.open(path, "r") do |f|
|
22
|
+
f.each_line.with_index do |line, _i|
|
23
|
+
if @on
|
24
|
+
new_line.write("\n" && break) if line.include?("t.index") || line.strip == "end"
|
25
|
+
field = '["tag1", "tag2", "tag3"]' if line.include?("array: true")
|
26
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
27
|
+
field ||= get_test_type(type)
|
28
|
+
if type == "bigint" && name.include?("_id")
|
29
|
+
id_name = name.gsub("_id", "")
|
30
|
+
new_line.write(" association :#{id_name}, factory: :#{id_name}\n")
|
31
|
+
else
|
32
|
+
new_line.write(" #{name} { #{field} }\n")
|
33
|
+
end
|
32
34
|
end
|
35
|
+
@on = true if table_check(line: line, class_name: class_name)
|
33
36
|
end
|
34
|
-
@on = true if table_check(line: line, class_name: class_name)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def rspec_factory_end(class_name: "user")
|
42
|
+
file_path = "./spec/factories/#{class_name.pluralize}.rb"
|
43
|
+
File.open(file_path, "a") do |f|
|
44
|
+
f.write(<<~TEXT)
|
45
|
+
end
|
44
46
|
end
|
45
|
-
|
46
|
-
|
47
|
+
TEXT
|
48
|
+
end
|
49
|
+
file_path
|
47
50
|
end
|
48
|
-
file_path
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def rspec_factory(class_name: "user")
|
53
|
+
file_path = "./spec/factories/#{class_name.pluralize}.rb"
|
54
|
+
return "RspecFactory already exist! #{file_path}" if File.exist?(file_path)
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
singularized_class_name = class_name.singularize
|
57
|
+
rspec_factory_head(class_name: singularized_class_name)
|
58
|
+
rspec_factory_params(class_name: singularized_class_name)
|
59
|
+
rspec_factory_end(class_name: singularized_class_name)
|
60
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
61
|
+
file_path
|
62
|
+
rescue StandardError => e
|
63
|
+
raise(StandardError, e)
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|