Sha256: 29489f35f17e7c10f1db60419975c21447560db1cfe5493d03c7d576f3616969

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true
module Decidim
  module Comments
    # This module's job is to extend the API with custom fields related to
    # decidim-comments.
    module QueryExtensions
      # Public: Extends a type with `decidim-comments`'s fields.
      #
      # type - A GraphQL::BaseType to extend.
      #
      # Returns nothing.
      def self.extend!(type)
        type.define do
          field :comments do
            description "Lists all commentable's comments."
            type !types[CommentType]

            argument :commentableId, !types.String, "The commentable's ID"
            argument :commentableType, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
            argument :orderBy, types.String, "Order the comments"

            resolve lambda { |_obj, args, _ctx|
              commentable = args[:commentableType].constantize.find(args[:commentableId])
              CommentsWithReplies.for(commentable, order_by: args[:orderBy])
            }
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
decidim-0.0.4 decidim-comments/lib/decidim/comments/query_extensions.rb
decidim-comments-0.0.3 lib/decidim/comments/query_extensions.rb
decidim-0.0.3 decidim-comments/lib/decidim/comments/query_extensions.rb
decidim-comments-0.0.2 lib/decidim/comments/query_extensions.rb
decidim-0.0.2 decidim-comments/lib/decidim/comments/query_extensions.rb