Skip to content

Commit

Permalink
HW12 [CreateTask, UpdateComment, DestroyProject] - Mutations (#144)
Browse files Browse the repository at this point in the history
* CreateTask

* add Destroy Project mutation

* add mutation update commit

* litte fixes

* return removed mutations

---------

Co-authored-by: deniszackharov <denis.zaharov@flatstack.com>
  • Loading branch information
NikitaEvstyagin and DenisZackharov committed Dec 20, 2023
1 parent dedba0a commit 0c06541
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/graphql/mutations/create_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Mutations
class CreateTask < BaseMutation
argument :input, Types::Inputs::CreateTaskInput, required: true

type Types::Payloads::TaskPayload

def resolve(input:)
input_params = input.to_h

result = Tasks::Create.call(
project: ::Project.find_by(id: input_params.delete(:project_id)),
task_params: input_params
)

result.to_h.merge(errors: formatted_errors(result.task))
end
end
end
18 changes: 18 additions & 0 deletions app/graphql/mutations/update_comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Mutations
class UpdateComment < BaseMutation
argument :input, Types::Inputs::UpdateCommentInput, required: true

type Types::Payloads::CommentPayload

def resolve(input:)
input_params = input.to_h

result = Comments::Update.call(
comment: Comment.find(input_params.delete(:id)),
comment_params: input_params
)

result.to_h.merge(errors: formatted_errors(result.comment))
end
end
end
11 changes: 11 additions & 0 deletions app/graphql/types/inputs/create_task_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Types
module Inputs
class CreateTaskInput < Types::BaseInputObject
argument :project_id, ID, required: true
argument :name, String, required: true
argument :description, String, required: false
argument :status, TaskStatusType, required: true
argument :deadline_at, GraphQL::Types::ISO8601DateTime, required: true
end
end
end
8 changes: 8 additions & 0 deletions app/graphql/types/inputs/update_comment_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Types
module Inputs
class UpdateCommentInput < Types::BaseInputObject
argument :id, ID, required: true
argument :content, String, required: false
end
end
end
9 changes: 5 additions & 4 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class MutationType < Types::BaseObject
field :update_project, mutation: Mutations::UpdateProject
field :destroy_project, mutation: Mutations::DestroyProject

field :update_task, mutation: Mutations::UpdateTask
field :create_task, mutation: Mutations::CreateTask
field :update_task, mutation: Mutations::UpdateTask

field :destroy_user, mutation: Mutations::DestroyUser
field :update_user, mutation: Mutations::UpdateUser
field :update_comment, mutation: Mutations::UpdateComment

field :create_comment, mutation: Mutations::CreateComment
field :update_user, mutation: Mutations::UpdateUser
field :destroy_user, mutation: Mutations::DestroyUser
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/payloads/task_payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Types
module Payloads
class TaskPayload < Types::BaseObject
field :task, TaskType, null: true
field :errors, [Types::UserError], null: false
field :errors, [Types::UserError], null: true
end
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class UserType < Types::BaseObject
field :first_name, String
field :last_name, String
field :email, String, null: false
field :role, UserRoleType, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :role, UserRoleType, null: false
end
end

0 comments on commit 0c06541

Please sign in to comment.