Sha256: b39d624e62815c2f9af22ced1579e2f0aa6f90379ccc9c014e3d29ec8c096e67

Contents?: true

Size: 807 Bytes

Versions: 10

Compression:

Stored size: 807 Bytes

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 QueryExtensions
      # 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 do
            type !CommentableType

            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
        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/query_extensions.rb
decidim-0.1.0 decidim-comments/lib/decidim/comments/query_extensions.rb
decidim-comments-0.0.8.1 lib/decidim/comments/query_extensions.rb
decidim-0.0.8.1 decidim-comments/lib/decidim/comments/query_extensions.rb
decidim-comments-0.0.7 lib/decidim/comments/query_extensions.rb
decidim-0.0.7 decidim-comments/lib/decidim/comments/query_extensions.rb
decidim-comments-0.0.6 lib/decidim/comments/query_extensions.rb
decidim-0.0.6 decidim-comments/lib/decidim/comments/query_extensions.rb
decidim-comments-0.0.5 lib/decidim/comments/query_extensions.rb
decidim-0.0.5 decidim-comments/lib/decidim/comments/query_extensions.rb