Skip to content

Commit

Permalink
Hw 12 v (#159)
Browse files Browse the repository at this point in the history
* added (DestoryProject, CreateTask, UpdateComment, DestroyComment)

* revert database.yml

---------

Co-authored-by: Denis Zakharov <78980031+DenisZackharov@users.noreply.github.com>
  • Loading branch information
LilVoidx and DenisZackharov committed Dec 20, 2023
1 parent 0c06541 commit 404ce4d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/graphql/mutations/destroy_comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Mutations
class DestroyComment < BaseMutation
argument :id, ID, required: true

type Types::Payloads::CommentPayload

def resolve(id:)
comment = Comment.find(id)

result = Comments::Destroy.call(comment: comment)

result.to_h.merge(errors: formatted_errors(result.comment))
end
end
end
10 changes: 10 additions & 0 deletions app/graphql/resolvers/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Resolvers
class Comment < Resolvers::Base
argument :id, ID, required: true
type Types::CommentType, null: true

def resolve(**args)
::Comment.find_by(id: args[:id])
end
end
end
9 changes: 9 additions & 0 deletions app/graphql/resolvers/comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Resolvers
class Comments < Resolvers::Base
type [Types::CommentType], null: true

def resolve(**_args)
::Comment.all
end
end
end
1 change: 1 addition & 0 deletions app/graphql/types/comment_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CommentType < Types::BaseObject
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :task, TaskType, null: false
field :user_id, Integer, null: false
field :user, UserType, null: false
end
end
2 changes: 2 additions & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class MutationType < Types::BaseObject
field :create_task, mutation: Mutations::CreateTask
field :update_task, mutation: Mutations::UpdateTask

field :create_comment, mutation: Mutations::CreateComment
field :update_comment, mutation: Mutations::UpdateComment
field :destroy_comment, mutation: Mutations::DestroyComment

field :update_user, mutation: Mutations::UpdateUser
field :destroy_user, mutation: Mutations::DestroyUser
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ class QueryType < Types::BaseObject
field :projects, resolver: Resolvers::Projects
field :task, resolver: Resolvers::Task
field :tasks, resolver: Resolvers::Tasks
field :comment, resolver: Resolvers::Comment
field :comments, resolver: Resolvers::Comments
end
end
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 404ce4d

Please sign in to comment.