Class: Decidim::Core::ComponentListBase
- Inherits:
-
GraphQL::Function
- Object
- GraphQL::Function
- Decidim::Core::ComponentListBase
- Includes:
- NeedsApiFilterAndOrder
- Defined in:
- app/functions/decidim/core/component_list_base.rb
Overview
A very basic resolver for the GraphQL endpoint for listing components Used in the keyword that lists some type of a specific component. For instance, “proposals” if it is a Proposal:
participatoryProcesses {
components {
... on Proposals {
proposals(...)
}
}
}
Needs to be extended and add arguments Usually something like:
class ProposalListHelper < Decidim::Core::ComponentListBase
argument :order, ProposalInputSort, "Provides several methods to order the results"
argument :filter, ProposalInputFilter, "Provides several methods to filter the results"
end
For an example check decidim-proposals/app/types/decidim/proposals/proposals_type.rb
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
- #call(component, args, _ctx) ⇒ Object
-
#initialize(model_class:) ⇒ ComponentListBase
constructor
A new instance of ComponentListBase.
-
#query_scope ⇒ Object
By default, any model uses the default scope for queries Particular implementations may restrict this by adding additional constrains.
Methods included from NeedsApiFilterAndOrder
#add_filter_keys, #add_order_keys
Constructor Details
#initialize(model_class:) ⇒ ComponentListBase
Returns a new instance of ComponentListBase.
32 33 34 |
# File 'app/functions/decidim/core/component_list_base.rb', line 32 def initialize(model_class:) @model_class = model_class end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
30 31 32 |
# File 'app/functions/decidim/core/component_list_base.rb', line 30 def model_class @model_class end |
Instance Method Details
#call(component, args, _ctx) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'app/functions/decidim/core/component_list_base.rb', line 36 def call(component, args, _ctx) @query = query_scope.where(component: component) .includes(:component) add_filter_keys(args[:filter]) order = filter_keys_by_settings(args[:order].to_h, component) add_order_keys(order) @query end |
#query_scope ⇒ Object
By default, any model uses the default scope for queries Particular implementations may restrict this by adding additional constrains
49 50 51 |
# File 'app/functions/decidim/core/component_list_base.rb', line 49 def query_scope model_class end |