Module: Decidim::Initiatives::QueryExtensions

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

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(type) ⇒ Object

Public: Extends a type with `decidim-initiatives`'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
34
35
36
# File 'decidim-initiatives/lib/decidim/initiatives/query_extensions.rb', line 13

def self.included(type)
  type.field :initiatives_types, [InitiativeApiType], null: false do
    description "Lists all initiative types"
  end

  type.field :initiatives_type, InitiativeApiType, null: true, description: "Finds a initiative type" do
    argument :id, GraphQL::Types::ID, "The ID of the initiative type", required: true
  end

  type.field :initiatives,
             [Decidim::Initiatives::InitiativeType],
             null: true,
             description: "Lists all initiatives" do
    argument :filter, Decidim::ParticipatoryProcesses::ParticipatoryProcessInputFilter, "This argument lets you filter the results", required: false
    argument :order, Decidim::ParticipatoryProcesses::ParticipatoryProcessInputSort, "This argument lets you order the results", required: false
  end

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

Instance Method Details

#initiative(id: nil) ⇒ Object


56
57
58
59
60
# File 'decidim-initiatives/lib/decidim/initiatives/query_extensions.rb', line 56

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

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

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


51
52
53
54
# File 'decidim-initiatives/lib/decidim/initiatives/query_extensions.rb', line 51

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

#initiatives_type(id:) ⇒ Object


44
45
46
47
48
49
# File 'decidim-initiatives/lib/decidim/initiatives/query_extensions.rb', line 44

def initiatives_type(id:)
  Decidim::InitiativesType.find_by(
    organization: context[:current_organization],
    id: id
  )
end

#initiatives_typesObject


38
39
40
41
42
# File 'decidim-initiatives/lib/decidim/initiatives/query_extensions.rb', line 38

def initiatives_types
  Decidim::InitiativesType.where(
    organization: context[:current_organization]
  )
end