Module: Decidim::Comments::QueryExtensions

Defined in:
decidim-comments/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.



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

def self.extend!(type)
  type.define do
    field :commentable do
      type !CommentableType

      argument :id, !types.String, "The commentable's ID"
      argument :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"

      resolve lambda { |_obj, args, _ctx|
        args[:type].constantize.find(args[:id])
      }
    end
  end
end