souls 0.22.4 → 0.22.8
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/Gemfile +1 -0
- data/Gemfile.lock +7 -2
- data/exe/souls +27 -6
- data/hoy/.env.sample +7 -0
- data/hoy/.gitignore +32 -0
- data/hoy/.irbrc +1 -0
- data/hoy/.rspec +3 -0
- data/hoy/.rubocop.yml +132 -0
- data/hoy/.ruby-version +1 -0
- data/hoy/CODE_OF_CONDUCT.md +74 -0
- data/hoy/Dockerfile +16 -0
- data/hoy/Dockerfile.dev +17 -0
- data/hoy/Gemfile +50 -0
- data/hoy/Gemfile.lock +407 -0
- data/hoy/LICENSE.txt +67 -0
- data/hoy/Procfile +2 -0
- data/hoy/Procfile.dev +2 -0
- data/hoy/README.md +61 -0
- data/hoy/Rakefile +5 -0
- data/hoy/app.rb +116 -0
- data/hoy/app/graphql/mutations/.keep +0 -0
- data/hoy/app/graphql/mutations/base/article/create_article.rb +30 -0
- data/hoy/app/graphql/mutations/base/article/delete_article.rb +17 -0
- data/hoy/app/graphql/mutations/base/article/destroy_delete_article.rb +17 -0
- data/hoy/app/graphql/mutations/base/article/update_article.rb +30 -0
- data/hoy/app/graphql/mutations/base/article_category/create_article_category.rb +21 -0
- data/hoy/app/graphql/mutations/base/article_category/delete_article_category.rb +17 -0
- data/hoy/app/graphql/mutations/base/article_category/destroy_delete_article_category.rb +17 -0
- data/hoy/app/graphql/mutations/base/article_category/update_article_category.rb +21 -0
- data/hoy/app/graphql/mutations/base/user/create_user.rb +31 -0
- data/hoy/app/graphql/mutations/base/user/delete_user.rb +17 -0
- data/hoy/app/graphql/mutations/base/user/destroy_delete_user.rb +17 -0
- data/hoy/app/graphql/mutations/base/user/update_user.rb +31 -0
- data/hoy/app/graphql/mutations/base_mutation.rb +33 -0
- data/hoy/app/graphql/mutations/user_manager/add_user_role.rb +22 -0
- data/hoy/app/graphql/mutations/user_manager/remove_user_role.rb +22 -0
- data/hoy/app/graphql/mutations/user_manager/sign_in_user.rb +45 -0
- data/hoy/app/graphql/queries/article.rb +13 -0
- data/hoy/app/graphql/queries/article_categories.rb +11 -0
- data/hoy/app/graphql/queries/article_category.rb +13 -0
- data/hoy/app/graphql/queries/articles.rb +11 -0
- data/hoy/app/graphql/queries/base_query.rb +9 -0
- data/hoy/app/graphql/queries/me.rb +11 -0
- data/hoy/app/graphql/queries/user.rb +13 -0
- data/hoy/app/graphql/queries/users.rb +11 -0
- data/hoy/app/graphql/resolvers/article_category_search.rb +41 -0
- data/hoy/app/graphql/resolvers/article_search.rb +57 -0
- data/hoy/app/graphql/resolvers/base.rb +17 -0
- data/hoy/app/graphql/resolvers/user_search.rb +63 -0
- data/hoy/app/graphql/souls_api_schema.rb +43 -0
- data/hoy/app/graphql/types/.keep +0 -0
- data/hoy/app/graphql/types/article_category_type.rb +12 -0
- data/hoy/app/graphql/types/article_type.rb +30 -0
- data/hoy/app/graphql/types/base/base_argument.rb +4 -0
- data/hoy/app/graphql/types/base/base_enum.rb +4 -0
- data/hoy/app/graphql/types/base/base_field.rb +5 -0
- data/hoy/app/graphql/types/base/base_input_object.rb +5 -0
- data/hoy/app/graphql/types/base/base_interface.rb +7 -0
- data/hoy/app/graphql/types/base/base_object.rb +6 -0
- data/hoy/app/graphql/types/base/base_scalar.rb +4 -0
- data/hoy/app/graphql/types/base/base_union.rb +4 -0
- data/hoy/app/graphql/types/base/mutation_type.rb +16 -0
- data/hoy/app/graphql/types/base/query_type.rb +18 -0
- data/hoy/app/graphql/types/connections/article_category_connection.rb +3 -0
- data/hoy/app/graphql/types/connections/article_connection.rb +3 -0
- data/hoy/app/graphql/types/connections/base_connection.rb +14 -0
- data/hoy/app/graphql/types/connections/user_connection.rb +3 -0
- data/hoy/app/graphql/types/edges/article_category_edge.rb +5 -0
- data/hoy/app/graphql/types/edges/article_edge.rb +5 -0
- data/hoy/app/graphql/types/edges/base_edge.rb +4 -0
- data/hoy/app/graphql/types/edges/user_edge.rb +5 -0
- data/hoy/app/graphql/types/user_type.rb +22 -0
- data/hoy/app/models/article.rb +4 -0
- data/hoy/app/models/article_category.rb +3 -0
- data/hoy/app/models/user.rb +19 -0
- data/hoy/app/policies/application_policy.rb +40 -0
- data/hoy/app/policies/article_category_policy.rb +31 -0
- data/hoy/app/policies/article_policy.rb +31 -0
- data/hoy/app/policies/user_policy.rb +35 -0
- data/hoy/app/utils/association_loader.rb +50 -0
- data/hoy/app/utils/firebase_id_token.rb +4 -0
- data/hoy/app/utils/json_web_token.rb +13 -0
- data/hoy/app/utils/record_loader.rb +10 -0
- data/hoy/app/utils/souls_helper.rb +96 -0
- data/hoy/cloudbuild.yml +32 -0
- data/hoy/config.ru +17 -0
- data/hoy/config/database.yml +33 -0
- data/hoy/config/souls.rb +4 -0
- data/hoy/constants/areas.rb +71 -0
- data/hoy/constants/column_name_ja.rb +27 -0
- data/hoy/db/migrate/20200006095538_create_users.rb +30 -0
- data/hoy/db/migrate/20200712180236_create_article_categories.rb +12 -0
- data/hoy/db/migrate/20200714215521_create_articles.rb +22 -0
- data/hoy/db/schema.rb +78 -0
- data/hoy/db/seeds.rb +44 -0
- data/hoy/github/workflows/delivery.yml +81 -0
- data/hoy/log/.keep +0 -0
- data/hoy/spec/factories/article_categories.rb +9 -0
- data/hoy/spec/factories/articles.rb +17 -0
- data/hoy/spec/factories/users.rb +23 -0
- data/hoy/spec/models/article_category_spec.rb +7 -0
- data/hoy/spec/models/article_spec.rb +7 -0
- data/hoy/spec/models/user_spec.rb +7 -0
- data/hoy/spec/mutations/base/article_category_spec.rb +46 -0
- data/hoy/spec/mutations/base/article_spec.rb +70 -0
- data/hoy/spec/mutations/base/user_spec.rb +76 -0
- data/hoy/spec/policies/article_category_policy_spec.rb +25 -0
- data/hoy/spec/policies/article_policy_spec.rb +25 -0
- data/hoy/spec/policies/user_policy_spec.rb +5 -0
- data/hoy/spec/queries/article_category_spec.rb +39 -0
- data/hoy/spec/queries/article_spec.rb +53 -0
- data/hoy/spec/queries/user_spec.rb +59 -0
- data/hoy/spec/resolvers/article_category_search_spec.rb +54 -0
- data/hoy/spec/resolvers/article_search_spec.rb +68 -0
- data/hoy/spec/resolvers/user_search_spec.rb +74 -0
- data/hoy/spec/spec_helper.rb +110 -0
- data/hoy/tmp/.keep +0 -0
- data/lib/souls.rb +47 -9
- data/lib/souls/generate/mutation.rb +4 -6
- data/lib/souls/init.rb +16 -9
- data/lib/souls/version.rb +1 -1
- data/souls.gemspec +3 -1
- metadata +146 -4
data/hoy/Procfile
ADDED
data/hoy/Procfile.dev
ADDED
data/hoy/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# SOULs Ruby GraphQL API Server
|
2
|
+
SOULs Ruby GraphQL API Server Boilerplate
|
3
|
+
|
4
|
+
<p align="center">
|
5
|
+
|
6
|
+
<a aria-label="Ruby logo" href="https://el-soul.com">
|
7
|
+
<img src="https://badgen.net/badge/icon/Made%20by%20ELSOUL?icon=ruby&label&color=black&labelColor=black">
|
8
|
+
</a>
|
9
|
+
<br/>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
git clone
|
15
|
+
|
16
|
+
```
|
17
|
+
git clone git@github.com:elsoul/souls_api.git
|
18
|
+
cd souls_api
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
# Run Server on local
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
souls s
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
## SOULs Document
|
31
|
+
|
32
|
+
- [SOULs Document](https://souls-doc.el-soul.com/)
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
You can see GraphQL Playground here;
|
38
|
+
|
39
|
+
`localhost:3000/playground`
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org/gems/souls_api).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/elsoul/souls_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [Apache-2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
|
58
|
+
|
59
|
+
## Code of Conduct
|
60
|
+
|
61
|
+
Everyone interacting in the HotelPrice project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/elsoul/souls_api/blob/master/CODE_OF_CONDUCT.md).
|
data/hoy/Rakefile
ADDED
data/hoy/app.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
require "erb"
|
4
|
+
require "jwt"
|
5
|
+
require "json"
|
6
|
+
require "sinatra"
|
7
|
+
require "sinatra/base"
|
8
|
+
require "sinatra/json"
|
9
|
+
require "psych"
|
10
|
+
require "sinatra/activerecord"
|
11
|
+
require "rack/contrib"
|
12
|
+
require "zeitwerk"
|
13
|
+
require "factory_bot"
|
14
|
+
require "faker"
|
15
|
+
require "dotenv/load"
|
16
|
+
require "firebase_id_token"
|
17
|
+
require "graphql"
|
18
|
+
require "google/cloud/firestore"
|
19
|
+
require "google/cloud/storage"
|
20
|
+
require "google/cloud/pubsub"
|
21
|
+
require "logger"
|
22
|
+
require "base64"
|
23
|
+
require "slack/ruby3"
|
24
|
+
require "role_model"
|
25
|
+
require "pundit"
|
26
|
+
require "sendgrid-ruby"
|
27
|
+
require "search_object"
|
28
|
+
require "search_object/plugin/graphql"
|
29
|
+
require "graphql/batch"
|
30
|
+
|
31
|
+
ENV["RACK_ENV"] ||= "development"
|
32
|
+
Dir["./config/*.rb"].each { |f| require f unless f.include?("souls.rb") }
|
33
|
+
Dir["./constants/*.rb"].each { |f| require f }
|
34
|
+
|
35
|
+
db_conf = YAML.safe_load(ERB.new(File.read("./config/database.yml")).result, permitted_classes: [Date], aliases: true)
|
36
|
+
ActiveRecord::Base.establish_connection(db_conf[ENV["RACK_ENV"]])
|
37
|
+
ActiveRecord::Base.default_timezone = :local
|
38
|
+
|
39
|
+
loader = Zeitwerk::Loader.new
|
40
|
+
loader.push_dir("#{Dir.pwd}/app/models")
|
41
|
+
loader.push_dir("#{Dir.pwd}/app/utils")
|
42
|
+
loader.push_dir("#{Dir.pwd}/app/policies")
|
43
|
+
|
44
|
+
loader.do_not_eager_load("#{Dir.pwd}/app/services")
|
45
|
+
loader.collapse("#{__dir__}/app/types")
|
46
|
+
loader.collapse("#{__dir__}/app/mutations")
|
47
|
+
loader.collapse("#{__dir__}/app/queries")
|
48
|
+
loader.collapse("#{__dir__}/app/services")
|
49
|
+
loader.collapse("#{__dir__}/app/resolvers")
|
50
|
+
loader.collapse("#{__dir__}/app/graphql/types/connections")
|
51
|
+
loader.collapse("#{__dir__}/app/graphql/types/edges")
|
52
|
+
loader.collapse("#{__dir__}/app/graphql/types/base")
|
53
|
+
loader.push_dir("#{Dir.pwd}/app/graphql")
|
54
|
+
loader.setup
|
55
|
+
|
56
|
+
class SoulsApi < Sinatra::Base
|
57
|
+
include Pundit
|
58
|
+
include SoulsHelper
|
59
|
+
::Logger.class_eval { alias_method :write, :<< }
|
60
|
+
access_log = ::File.join(::File.dirname(::File.expand_path(__FILE__)), "log", "access.log")
|
61
|
+
access_logger = ::Logger.new(access_log)
|
62
|
+
error_logger = ::File.new(::File.join(::File.dirname(::File.expand_path(__FILE__)), "log", "error.log"), "a+")
|
63
|
+
error_logger.sync = true
|
64
|
+
|
65
|
+
use Rack::JSONBodyParser
|
66
|
+
register Sinatra::ActiveRecordExtension
|
67
|
+
|
68
|
+
configure :production, :development do
|
69
|
+
set :logger, Logger.new($stdout)
|
70
|
+
enable :logging
|
71
|
+
use ::Rack::CommonLogger, access_logger
|
72
|
+
end
|
73
|
+
|
74
|
+
before { env["rack.errors"] = error_logger }
|
75
|
+
|
76
|
+
error StandardError do
|
77
|
+
StandardError.to_json
|
78
|
+
end
|
79
|
+
|
80
|
+
get "/" do
|
81
|
+
message = { success: true, message: "SOULs Running!", env: ENV["RACK_ENV"] }
|
82
|
+
json message
|
83
|
+
end
|
84
|
+
|
85
|
+
get "/db" do
|
86
|
+
message = { success: true, message: "SOULs Running!", env: ENV["RACK_ENV"], db: User.first.username }
|
87
|
+
json(message)
|
88
|
+
rescue StandardError => e
|
89
|
+
message = { error: e }
|
90
|
+
json(message)
|
91
|
+
end
|
92
|
+
|
93
|
+
post "/endpoint" do
|
94
|
+
token = request.env["HTTP_AUTHORIZATION"].split("Bearer ")[1] if request.env["HTTP_AUTHORIZATION"]
|
95
|
+
|
96
|
+
user = token ? login_auth(token: token) : nil
|
97
|
+
context = { user: user }
|
98
|
+
result = SoulsApiSchema.execute(params[:query], variables: params[:variables], context: context)
|
99
|
+
json(result)
|
100
|
+
rescue StandardError => e
|
101
|
+
message = { error: e }
|
102
|
+
json(message)
|
103
|
+
end
|
104
|
+
|
105
|
+
def login_auth(token:)
|
106
|
+
decoded_token = JsonWebToken.decode(token)
|
107
|
+
user_id = decoded_token[:user_id]
|
108
|
+
user = User.find(user_id)
|
109
|
+
raise(StandardError, "Invalid or Missing Token") if user.blank?
|
110
|
+
|
111
|
+
user
|
112
|
+
rescue StandardError => e
|
113
|
+
message = { error: e }
|
114
|
+
json(message)
|
115
|
+
end
|
116
|
+
end
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::Article
|
3
|
+
class CreateArticle < BaseMutation
|
4
|
+
field :article_edge, Types::ArticleType.edge_type, null: false
|
5
|
+
field :error, String, null: true
|
6
|
+
|
7
|
+
argument :article_category_id, String, required: false
|
8
|
+
argument :body, String, required: false
|
9
|
+
argument :is_deleted, Boolean, required: false
|
10
|
+
argument :is_public, Boolean, required: false
|
11
|
+
argument :just_created, Boolean, required: false
|
12
|
+
argument :public_date, String, required: false
|
13
|
+
argument :slag, String, required: false
|
14
|
+
argument :tags, [String], required: false
|
15
|
+
argument :thumnail_url, String, required: false
|
16
|
+
argument :title, String, required: false
|
17
|
+
|
18
|
+
def resolve(**args)
|
19
|
+
args[:user_id] = context[:user].id
|
20
|
+
_, args[:article_category_id] = SoulsApiSchema.from_global_id(args[:article_category_id])
|
21
|
+
data = ::Article.new(args)
|
22
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
23
|
+
|
24
|
+
{ article_edge: { node: data } }
|
25
|
+
rescue StandardError => e
|
26
|
+
GraphQL::ExecutionError.new(e)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::Article
|
3
|
+
class DeleteArticle < BaseMutation
|
4
|
+
field :article, Types::ArticleType, null: false
|
5
|
+
argument :id, String, required: true
|
6
|
+
|
7
|
+
def resolve(**args)
|
8
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
9
|
+
article = ::Article.find(data_id)
|
10
|
+
article.update(is_deleted: true)
|
11
|
+
{ article: ::Article.find(data_id) }
|
12
|
+
rescue StandardError => e
|
13
|
+
GraphQL::ExecutionError.new(e)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::Article
|
3
|
+
class DestroyDeleteArticle < BaseMutation
|
4
|
+
field :article, Types::ArticleType, null: false
|
5
|
+
argument :id, String, required: true
|
6
|
+
|
7
|
+
def resolve(**args)
|
8
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
9
|
+
article = ::Article.find(data_id)
|
10
|
+
article.destroy
|
11
|
+
{ article: article }
|
12
|
+
rescue StandardError => e
|
13
|
+
GraphQL::ExecutionError.new(e)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::Article
|
3
|
+
class UpdateArticle < BaseMutation
|
4
|
+
field :article_edge, Types::ArticleType.edge_type, null: false
|
5
|
+
|
6
|
+
argument :article_category_id, String, required: false
|
7
|
+
argument :body, String, required: false
|
8
|
+
argument :id, String, required: true
|
9
|
+
argument :is_deleted, Boolean, required: false
|
10
|
+
argument :is_public, Boolean, required: false
|
11
|
+
argument :just_created, Boolean, required: false
|
12
|
+
argument :public_date, GraphQL::Types::ISO8601DateTime, required: false
|
13
|
+
argument :slag, String, required: false
|
14
|
+
argument :tags, [String], required: false
|
15
|
+
argument :thumnail_url, String, required: false
|
16
|
+
argument :title, String, required: false
|
17
|
+
|
18
|
+
def resolve(**args)
|
19
|
+
args[:user_id] = context[:user].id
|
20
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
21
|
+
_, args[:article_category_id] = SoulsApiSchema.from_global_id(args[:article_category_id])
|
22
|
+
article = ::Article.find(args[:id])
|
23
|
+
article.update(args)
|
24
|
+
{ article_edge: { node: ::Article.find(args[:id]) } }
|
25
|
+
rescue StandardError => e
|
26
|
+
GraphQL::ExecutionError.new(e)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::ArticleCategory
|
3
|
+
class CreateArticleCategory < BaseMutation
|
4
|
+
field :article_category_edge, Types::ArticleCategoryType.edge_type, null: false
|
5
|
+
field :error, String, null: true
|
6
|
+
|
7
|
+
argument :is_deleted, Boolean, required: false
|
8
|
+
argument :name, String, required: false
|
9
|
+
argument :tags, [String], required: false
|
10
|
+
|
11
|
+
def resolve(**args)
|
12
|
+
data = ::ArticleCategory.new(args)
|
13
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
14
|
+
|
15
|
+
{ article_category_edge: { node: data } }
|
16
|
+
rescue StandardError => e
|
17
|
+
GraphQL::ExecutionError.new(e)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::ArticleCategory
|
3
|
+
class DeleteArticleCategory < BaseMutation
|
4
|
+
field :article_category, Types::ArticleCategoryType, null: false
|
5
|
+
argument :id, String, required: true
|
6
|
+
|
7
|
+
def resolve(**args)
|
8
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
9
|
+
article_category = ::ArticleCategory.find(data_id)
|
10
|
+
article_category.update(is_deleted: true)
|
11
|
+
{ article_category: ::ArticleCategory.find(data_id) }
|
12
|
+
rescue StandardError => e
|
13
|
+
GraphQL::ExecutionError.new(e)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::ArticleCategory
|
3
|
+
class DestroyDeleteArticleCategory < BaseMutation
|
4
|
+
field :article_category, Types::ArticleCategoryType, null: false
|
5
|
+
argument :id, String, required: true
|
6
|
+
|
7
|
+
def resolve(**args)
|
8
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
9
|
+
article_category = ::ArticleCategory.find(data_id)
|
10
|
+
article_category.destroy
|
11
|
+
{ article_category: article_category }
|
12
|
+
rescue StandardError => e
|
13
|
+
GraphQL::ExecutionError.new(e)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::ArticleCategory
|
3
|
+
class UpdateArticleCategory < BaseMutation
|
4
|
+
field :article_category_edge, Types::ArticleCategoryType.edge_type, null: false
|
5
|
+
|
6
|
+
argument :id, String, required: true
|
7
|
+
argument :is_deleted, Boolean, required: false
|
8
|
+
argument :name, String, required: false
|
9
|
+
argument :tags, [String], required: false
|
10
|
+
|
11
|
+
def resolve(**args)
|
12
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
13
|
+
article_category = ::ArticleCategory.find(args[:id])
|
14
|
+
article_category.update(args)
|
15
|
+
{ article_category_edge: { node: ::ArticleCategory.find(args[:id]) } }
|
16
|
+
rescue StandardError => e
|
17
|
+
GraphQL::ExecutionError.new(e)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::User
|
3
|
+
class CreateUser < BaseMutation
|
4
|
+
field :error, String, null: true
|
5
|
+
field :user_edge, Types::UserType.edge_type, null: false
|
6
|
+
|
7
|
+
argument :birthday, String, required: false
|
8
|
+
argument :email, String, required: false
|
9
|
+
argument :first_name, String, required: false
|
10
|
+
argument :first_name_kana, String, required: false
|
11
|
+
argument :first_name_kanji, String, required: false
|
12
|
+
argument :icon_url, String, required: false
|
13
|
+
argument :last_name, String, required: false
|
14
|
+
argument :last_name_kana, String, required: false
|
15
|
+
argument :last_name_kanji, String, required: false
|
16
|
+
argument :screen_name, String, required: false
|
17
|
+
argument :tel, String, required: false
|
18
|
+
argument :uid, String, required: false
|
19
|
+
argument :username, String, required: false
|
20
|
+
|
21
|
+
def resolve(**args)
|
22
|
+
data = ::User.new(args)
|
23
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
24
|
+
|
25
|
+
{ user_edge: { node: data } }
|
26
|
+
rescue StandardError => e
|
27
|
+
GraphQL::ExecutionError.new(e)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::User
|
3
|
+
class DeleteUser < BaseMutation
|
4
|
+
field :user, Types::UserType, null: false
|
5
|
+
argument :id, String, required: true
|
6
|
+
|
7
|
+
def resolve(**args)
|
8
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
9
|
+
user = ::User.find(data_id)
|
10
|
+
user.update(is_deleted: true)
|
11
|
+
{ user: ::User.find(data_id) }
|
12
|
+
rescue StandardError => e
|
13
|
+
GraphQL::ExecutionError.new(e)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mutations
|
2
|
+
module Base::User
|
3
|
+
class DestroyDeleteUser < BaseMutation
|
4
|
+
field :user, Types::UserType, null: false
|
5
|
+
argument :id, String, required: true
|
6
|
+
|
7
|
+
def resolve(**args)
|
8
|
+
_, data_id = SoulsApiSchema.from_global_id(args[:id])
|
9
|
+
user = ::User.find(data_id)
|
10
|
+
user.destroy
|
11
|
+
{ user: user }
|
12
|
+
rescue StandardError => e
|
13
|
+
GraphQL::ExecutionError.new(e)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|