Module: Decidim::Comments::MutationExtensions
- Defined in:
- decidim-comments/lib/decidim/comments/mutation_extensions.rb
Overview
This module’s job is to extend the API with custom fields related to decidim-comments.
Class Method Summary collapse
-
.included(type) ⇒ Object
Public: Extends a type with ‘decidim-comments`’s fields.
Instance Method Summary collapse
- #comment(id:, locale: Decidim.default_locale, toggle_translations: false) ⇒ Object
- #commentable(id:, type:, locale: Decidim.default_locale, toggle_translations: false) ⇒ Object
Class Method Details
.included(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 27 28 29 30 |
# File 'decidim-comments/lib/decidim/comments/mutation_extensions.rb', line 13 def self.included(type) type.field :commentable, Decidim::Comments::CommentableMutationType, null: false do description "A commentable" 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: false argument :toggle_translations, GraphQL::Types::Boolean, "Whether the user asked to toggle the machine translations or not.", required: false end type.field :comment, Decidim::Comments::CommentMutationType, null: false do description "A comment" argument :id, GraphQL::Types::ID, "The comment's id", required: true argument :locale, GraphQL::Types::String, "The locale for which to get the comments text", required: false argument :toggle_translations, GraphQL::Types::Boolean, "Whether the user asked to toggle the machine translations or not.", required: false end end |
Instance Method Details
#comment(id:, locale: Decidim.default_locale, toggle_translations: false) ⇒ Object
38 39 40 41 42 |
# File 'decidim-comments/lib/decidim/comments/mutation_extensions.rb', line 38 def comment(id:, locale: Decidim.default_locale, toggle_translations: false) I18n.locale = locale.presence RequestStore.store[:toggle_machine_translations] = toggle_translations Comment.find(id) end |
#commentable(id:, type:, locale: Decidim.default_locale, toggle_translations: false) ⇒ Object
32 33 34 35 36 |
# File 'decidim-comments/lib/decidim/comments/mutation_extensions.rb', line 32 def commentable(id:, type:, locale: Decidim.default_locale, toggle_translations: false) I18n.locale = locale.presence RequestStore.store[:toggle_machine_translations] = toggle_translations type.constantize.find(id) end |