Class: Decidim::Comments::VoteCommentResolver

Inherits:
Object
  • Object
show all
Defined in:
decidim-comments/app/resolvers/decidim/comments/vote_comment_resolver.rb

Overview

A GraphQL resolver to handle ‘upVote` and `downVote` mutations It creates a vote for a comment by the current user.

Instance Method Summary collapse

Constructor Details

#initialize(options = { weight: 1 }) ⇒ VoteCommentResolver

Returns a new instance of VoteCommentResolver.



8
9
10
# File 'decidim-comments/app/resolvers/decidim/comments/vote_comment_resolver.rb', line 8

def initialize(options = { weight: 1 })
  @weight = options[:weight]
end

Instance Method Details

#call(obj, _args, ctx) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'decidim-comments/app/resolvers/decidim/comments/vote_comment_resolver.rb', line 12

def call(obj, _args, ctx)
  Decidim::Comments::VoteComment.call(obj, ctx[:current_user], weight: @weight) do
    on(:ok) do |comment|
      return comment
    end
    on(:invalid) do
      return GraphQL::ExecutionError.new(I18n.t("votes.create.error", scope: "decidim.comments"))
    end
  end
end