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.4.1 lib/decidim/comments/mutation_extensions.rb
decidim-0.4.3 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-0.4.2 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-0.4.1 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.4.0 lib/decidim/comments/mutation_extensions.rb
decidim-0.4.0 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.3.2 lib/decidim/comments/mutation_extensions.rb
decidim-0.3.2 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.3.1 lib/decidim/comments/mutation_extensions.rb
decidim-0.3.1 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.3.0 lib/decidim/comments/mutation_extensions.rb
decidim-0.3.0 decidim-comments/lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.2.0 lib/decidim/comments/mutation_extensions.rb
decidim-0.2.0 decidim-comments/lib/decidim/comments/mutation_extensions.rb