Sha256: e58060648c644c3dab09f04685391cd8efb50cb06c27d142bf57a5e458852abc

Contents?: true

Size: 1.58 KB

Versions: 28

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    # This interface represents a commentable object.
    CommentableInterface = GraphQL::InterfaceType.define do
      name "CommentableInterface"
      description "A commentable interface"

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

      field :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`" do
        property :commentable_type
      end

      field :acceptsNewComments, !types.Boolean, "Whether the object can have new comments or not" do
        property :accepts_new_comments?
      end

      field :commentsHaveAlignment, !types.Boolean, "Whether the object comments have alignment or not" do
        property :comments_have_alignment?
      end

      field :commentsHaveVotes, !types.Boolean, "Whether the object comments have votes or not" do
        property :comments_have_votes?
      end

      field :comments do
        type !types[!CommentType]

        argument :orderBy, types.String, "Order the comments"

        resolve lambda { |obj, args, _ctx|
          SortedComments.for(obj, order_by: args[:orderBy])
        }
      end

      field :totalCommentsCount do
        type !types.Int
        description "The number of comments in all levels this resource holds"

        resolve lambda { |obj, _args, _ctx|
          obj.comments.count
        }
      end

      field :hasComments, !types.Boolean, "Check if the commentable has comments" do
        resolve lambda { |obj, _args, _ctx|
          obj.comment_threads.size.positive?
        }
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
decidim-comments-0.17.2 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.17.1 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.16.1 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.17.0 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.16.0 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.15.2 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.15.1 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.15.0 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.14.4 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.14.3 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.14.2 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.14.1 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.13.1 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.12.2 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.13.0 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.12.1 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.13.0.pre1 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.12.0 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.11.2 app/types/decidim/comments/commentable_interface.rb
decidim-comments-0.12.0.pre app/types/decidim/comments/commentable_interface.rb