Sha256: 9fd787447294879bf41c0acc7ce8b171e41d5ab17b60573a8caefd7eec450062

Contents?: true

Size: 1.62 KB

Versions: 6

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module Decidim
  module EnhancedTextwork
    class ParagraphListHelper < Decidim::Core::ComponentListBase
      # only querying published posts
      def query_scope
        super.published
      end
    end

    class ParagraphFinderHelper < Decidim::Core::ComponentFinderBase
      # only querying published posts
      def query_scope
        super.published
      end
    end

    class ParagraphsType < Decidim::Api::Types::BaseObject
      implements Decidim::Core::ComponentInterface

      graphql_name "Paragraphs"
      description "A paragraphs component of a participatory space."

      field :paragraphs, type: Decidim::EnhancedTextwork::ParagraphType.connection_type, description: "List all paragraphs", connection: true, null: true do
        argument :order, Decidim::EnhancedTextwork::ParagraphInputSort, "Provides several methods to order the results", required: false
        argument :filter, Decidim::EnhancedTextwork::ParagraphInputFilter, "Provides several methods to filter the results", required: false
      end

      field :paragraph, type: Decidim::EnhancedTextwork::ParagraphType, description: "Finds one paragraph", null: true do
        argument :id, GraphQL::Types::ID, "The ID of the paragraph", required: true
      end

      def paragraphs(filter: {}, order: {})
        Decidim::EnhancedTextwork::ParagraphListHelper.new(model_class: Paragraph).call(object, { filter: filter, order: order }, context)
      end

      def paragraph(id:)
        Decidim::EnhancedTextwork::ParagraphFinderHelper.new(model_class: Paragraph).call(object, { id: id }, context)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-enhanced_textwork-1.0.5 lib/decidim/api/paragraphs_type.rb
decidim-enhanced_textwork-1.0.4 lib/decidim/api/paragraphs_type.rb
decidim-enhanced_textwork-1.0.3 lib/decidim/api/paragraphs_type.rb
decidim-enhanced_textwork-1.0.2 lib/decidim/api/paragraphs_type.rb
decidim-enhanced_textwork-1.0.1 lib/decidim/api/paragraphs_type.rb
decidim-enhanced_textwork-1.0.0 lib/decidim/api/paragraphs_type.rb