Module: Decidim::Assemblies::QueryExtensions

Defined in:
decidim-assemblies/lib/decidim/assemblies/query_extensions.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(type) ⇒ Object

Public: Extends a type with `decidim-assemblies`'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
29
30
31
32
33
# File 'decidim-assemblies/lib/decidim/assemblies/query_extensions.rb', line 13

def self.included(type)
  type.field :assemblies_types, [AssembliesTypeType], null: false, description: "Lists all assemblies types"

  type.field :assemblies_type, AssembliesTypeType, null: true, description: "Finds an assemblies type group" do
    argument :id, GraphQL::Types::ID, description: "The ID of the Assemblies type", required: true
  end
  type.field :assemblies,
             [Decidim::Assemblies::AssemblyType],
             null: true,
             description: "Lists all assemblies" 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 :assembly,
             Decidim::Assemblies::AssemblyType,
             null: true,
             description: "Finds a assembly" do
    argument :id, GraphQL::Types::ID, "The ID of the participatory space", required: false
  end
end

Instance Method Details

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


48
49
50
51
# File 'decidim-assemblies/lib/decidim/assemblies/query_extensions.rb', line 48

def assemblies(filter: {}, order: {})
  manifest = Decidim.participatory_space_manifests.select { |m| m.name == :assemblies }.first
  Decidim::Core::ParticipatorySpaceListBase.new(manifest: manifest).call(object, { filter: filter, order: order }, context)
end

#assemblies_type(id:) ⇒ Object


41
42
43
44
45
46
# File 'decidim-assemblies/lib/decidim/assemblies/query_extensions.rb', line 41

def assemblies_type(id:)
  Decidim::AssembliesType.find_by(
    organization: context[:current_organization],
    id: id
  )
end

#assemblies_typesObject


35
36
37
38
39
# File 'decidim-assemblies/lib/decidim/assemblies/query_extensions.rb', line 35

def assemblies_types(*)
  Decidim::AssembliesType.where(
    organization: context[:current_organization]
  )
end

#assembly(id: nil) ⇒ Object


53
54
55
56
# File 'decidim-assemblies/lib/decidim/assemblies/query_extensions.rb', line 53

def assembly(id: nil)
  manifest = Decidim.participatory_space_manifests.select { |m| m.name == :assemblies }.first
  Decidim::Core::ParticipatorySpaceFinderBase.new(manifest: manifest).call(object, { id: id }, context)
end