Module: Decidim::Comments::QueryExtensions

Defined in:
lib/decidim/comments/query_extensions.rb

Overview

This module’s job is to extend the API with custom fields related to decidim-comments.

Class Method Summary collapse

Class Method Details

.extend!(type) ⇒ Object

Public: Extends a type with ‘decidim-comments`’s fields.

type - A GraphQL::BaseType to extend.

Returns nothing.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/decidim/comments/query_extensions.rb', line 12

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