Module: Decidim::Votings::QueryExtensions

Defined in:
decidim-elections/lib/decidim/votings/query_extensions.rb

Overview

This module's job is to extend the API with custom fields related to decidim-votings.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(type) ⇒ Object

Public: Extends a type with `decidim-votings`'s fields.

type - A GraphQL::BaseType to extend.

Returns nothing.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'decidim-elections/lib/decidim/votings/query_extensions.rb', line 13

def self.included(type)
  type.field :votings,
             [Decidim::Votings::VotingType],
             null: true,
             description: "Lists all votings" do
    argument :filter, Decidim::ParticipatoryProcesses::ParticipatoryProcessInputFilter, "This argument let's you filter the results", required: false
    argument :order, Decidim::ParticipatoryProcesses::ParticipatoryProcessInputSort, "This argument let's you order the results", required: false
  end

  type.field :voting,
             Decidim::Votings::VotingType,
             null: true,
             description: "Finds a voting" do
    argument :id, GraphQL::Types::ID, "The ID of the participatory space", required: false
  end
end

Instance Method Details

#voting(id: nil) ⇒ Object


36
37
38
39
40
# File 'decidim-elections/lib/decidim/votings/query_extensions.rb', line 36

def voting(id: nil)
  manifest = Decidim.participatory_space_manifests.select { |m| m.name == :votings }.first

  Decidim::Core::ParticipatorySpaceFinderBase.new(manifest: manifest).call(object, { id: id }, context)
end

#votings(filter: {}, order: {}) ⇒ Object


30
31
32
33
34
# File 'decidim-elections/lib/decidim/votings/query_extensions.rb', line 30

def votings(filter: {}, order: {})
  manifest = Decidim.participatory_space_manifests.select { |m| m.name == :votings }.first

  Decidim::Core::ParticipatorySpaceListBase.new(manifest: manifest).call(object, { filter: filter, order: order }, context)
end