Sha256: eb20c098bfa70f6cc5236f8fbff3d5ade15928249c34eb98c8afb75ae3f19672

Contents?: true

Size: 1.06 KB

Versions: 32

Compression:

Stored size: 1.06 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.define(type)
        type.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

        type.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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
decidim-comments-0.22.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.21.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.20.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.20.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.19.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.18.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.19.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.17.2 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.18.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.17.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.16.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.17.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.16.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.15.2 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.15.1 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.15.0 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.14.4 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.14.3 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.14.2 lib/decidim/comments/mutation_extensions.rb
decidim-comments-0.14.1 lib/decidim/comments/mutation_extensions.rb