Sha256: 276cabebe1f6d8b41f99143adbd24e5a77caeb277fdf35883957acf7c7359889

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    CommentableMutationType = GraphQL::ObjectType.define do
      name "CommentableMutation"
      description "A commentable which includes its available mutations"

      field :id, !types.ID, "The Commentable's unique ID"

      field :addComment, Decidim::Comments::CommentType do
        description "Add a new comment to a commentable"

        argument :body, !types.String, "The comments's body"
        argument :alignment, types.Int, "The comment's alignment. Can be 0 (neutral), 1 (in favor) or -1 (against)'", default_value: 0
        argument :userGroupId, types.ID, "The comment's user group id. Replaces the author."

        resolve lambda { |obj, args, ctx|
          params = { "comment" => { "body" => args[:body], "alignment" => args[:alignment], "user_group_id" => args[:userGroupId], "commentable" => obj } }
          form = Decidim::Comments::CommentForm.from_params(params).with_context(
            current_organization: ctx[:current_organization],
            current_component: obj.component
          )
          Decidim::Comments::CreateComment.call(form, ctx[:current_user]) do
            on(:ok) do |comment|
              return comment
            end
          end
        }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-comments-0.23.6 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.23.5 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.23.4 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.23.3 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.23.2 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.23.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.23.1.rc1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.23.0 app/types/decidim/comments/commentable_mutation_type.rb