Sha256: 4ce426c010fb83f40d51fd15551fd6fccbbc64d80f0f56b120c5afda2a294f96

Contents?: true

Size: 1.19 KB

Versions: 31

Compression:

Stored size: 1.19 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] } }
          form = Decidim::Comments::CommentForm.from_params(params).with_context(current_organization: ctx[:current_organization])
          Decidim::Comments::CreateComment.call(form, ctx[:current_user], obj) do
            on(:ok) do |comment|
              return comment
            end
          end
        }
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-comments-0.21.0 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.20.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.20.0 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.19.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.18.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.19.0 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.17.2 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.18.0 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.17.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.16.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.17.0 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.16.0 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.15.2 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.15.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.15.0 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.14.4 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.14.3 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.14.2 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.14.1 app/types/decidim/comments/commentable_mutation_type.rb
decidim-comments-0.13.1 app/types/decidim/comments/commentable_mutation_type.rb