Sha256: 7fa7c184a919769513a1674637463b61f2f5ac9eba11c60a5b4da6c05bf5a4ec

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 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 MutationExtensions
      # Public: Extends a type with `decidim-comments`'s fields.
      #
      # type - A GraphQL::BaseType to extend.
      #
      # Returns nothing.
      def self.extend!(type)
        type.define do
          field :commentable, Decidim::Comments::CommentableMutationType do
            description "A commentable"

            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

          field :comment, Decidim::Comments::CommentMutationType do
            description "A comment"

            argument :id, !types.ID, "The comment's id"

            resolve lambda { |_obj, args, _ctx|
              Comment.find(args["id"])
            }
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
decidim-comments-0.1.0 lib/decidim/comments/mutation_extensions.rb
decidim-0.1.0 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.0.8.1 lib/decidim/comments/mutation_extensions.rb
decidim-0.0.8.1 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.0.7 lib/decidim/comments/mutation_extensions.rb
decidim-0.0.7 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.0.6 lib/decidim/comments/mutation_extensions.rb
decidim-0.0.6 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.0.5 lib/decidim/comments/mutation_extensions.rb
decidim-0.0.5 decidim-comments/lib/decidim/comments/mutation_extensions.rb