Sha256: 412b7b58e37299021742b8dab854d142cfb4386275bfb9844ecad39892f3130a

Contents?: true

Size: 1.16 KB

Versions: 50

Compression:

Stored size: 1.16 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.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

      def commentable(id:, locale:, toggle_translations:, type:)
        I18n.locale = locale.presence
        RequestStore.store[:toggle_machine_translations] = toggle_translations
        type.constantize.find(id)
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
decidim-comments-0.29.1 lib/decidim/comments/query_extensions.rb
decidim-comments-0.28.4 lib/decidim/comments/query_extensions.rb
decidim-comments-0.27.9 lib/decidim/comments/query_extensions.rb
decidim-comments-0.29.0 lib/decidim/comments/query_extensions.rb
decidim-comments-0.28.3 lib/decidim/comments/query_extensions.rb
decidim-comments-0.27.8 lib/decidim/comments/query_extensions.rb
decidim-comments-0.29.0.rc4 lib/decidim/comments/query_extensions.rb
decidim-comments-0.29.0.rc3 lib/decidim/comments/query_extensions.rb
decidim-comments-0.29.0.rc2 lib/decidim/comments/query_extensions.rb
decidim-comments-0.29.0.rc1 lib/decidim/comments/query_extensions.rb
decidim-comments-0.28.2 lib/decidim/comments/query_extensions.rb
decidim-comments-0.27.7 lib/decidim/comments/query_extensions.rb
decidim-comments-0.28.1 lib/decidim/comments/query_extensions.rb
decidim-comments-0.27.6 lib/decidim/comments/query_extensions.rb
decidim-comments-0.26.10 lib/decidim/comments/query_extensions.rb
decidim-comments-0.26.9 lib/decidim/comments/query_extensions.rb
decidim-comments-0.28.0 lib/decidim/comments/query_extensions.rb
decidim-comments-0.27.5 lib/decidim/comments/query_extensions.rb
decidim-comments-0.28.0.rc5 lib/decidim/comments/query_extensions.rb
decidim-comments-0.28.0.rc4 lib/decidim/comments/query_extensions.rb