Sha256: c3f4f9ce28df58f662522823ac4e1b659fa630caaf864a156aa738c388ea0882

Contents?: true

Size: 862 Bytes

Versions: 2

Compression:

Stored size: 862 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    ProposalsType = GraphQL::ObjectType.define do
      interfaces [-> { Decidim::Core::ComponentInterface }]

      name "Proposals"
      description "A proposals component of a participatory space."

      connection :proposals, ProposalType.connection_type do
        resolve ->(feature, _args, _ctx) {
                  ProposalsTypeHelper.base_scope(feature).includes(:feature)
                }
      end

      field(:proposal, ProposalType) do
        argument :id, !types.ID

        resolve ->(feature, args, _ctx) {
          ProposalsTypeHelper.base_scope(feature).find_by(id: args[:id])
        }
      end
    end

    module ProposalsTypeHelper
      def self.base_scope(feature)
        Proposal
          .where(feature: feature)
          .published
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-proposals-0.10.1 app/types/decidim/proposals/proposals_type.rb
decidim-proposals-0.10.0 app/types/decidim/proposals/proposals_type.rb