module Decidim::Comments::QueryExtensions

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

Public Class Methods

included(type) click to toggle source

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

type - A GraphQL::BaseType to extend.

Returns nothing.

# File lib/decidim/comments/query_extensions.rb, line 13
def self.included(type)
  type.field :commentable, CommentableType, null: false do
    argument :id, GraphQL::Types::String, "The commentable's ID", required: true
    argument :type, GraphQL::Types::String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`", required: true
    argument :locale, GraphQL::Types::String, "The locale for which to get the comments text", required: true
    argument :toggle_translations, GraphQL::Types::Boolean, "Whether the user asked to toggle the machine translations or not.", required: true
  end
end

Public Instance Methods

commentable(id:, locale:, toggle_translations:, type:) click to toggle source
# File lib/decidim/comments/query_extensions.rb, line 22
def commentable(id:, locale:, toggle_translations:, type:)
  I18n.locale = locale.presence
  RequestStore.store[:toggle_machine_translations] = toggle_translations
  type.constantize.find(id)
end