Sha256: 251c9cd690851253de3e35f69aaa9512978ca0ad7ade1125050a409dfe8504c2

Contents?: true

Size: 1.11 KB

Versions: 54

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

54 entries across 54 versions & 2 rubygems

Version Path
decidim-comments-0.9.3 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.9.2 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.9.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.9.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.8.4 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.8.3 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.8.2 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.8.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.8.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.7.4 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.7.3 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.7.2 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.7.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.7.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.6.8 lib/decidim/comments/mutation_extensions.rb
decidim-0.6.8 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.6.7 lib/decidim/comments/mutation_extensions.rb
decidim-0.6.7 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.6.6 lib/decidim/comments/mutation_extensions.rb
decidim-0.6.6 decidim-comments/lib/decidim/comments/mutation_extensions.rb