Class: Decidim::Core::ComponentFinderBase

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/api/functions/component_finder_base.rb

Overview

An abstract class with the logic for the GraphQL endpoint for a single component to be searchable. Normal components (such as Proposal) can inherit from this class and just add the needed search arguments

Usually something like:

class ProposalFinderHelper < Decidim::Core::ComponentFinderBase
  argument :id, !types.ID, "The ID of the proposal"
end

For an example check decidim-proposals/app/types/decidim/proposals/proposals_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class:) ⇒ ComponentFinderBase

Returns a new instance of ComponentFinderBase.



20
21
22
# File 'lib/decidim/api/functions/component_finder_base.rb', line 20

def initialize(model_class:)
  @model_class = model_class
end

Instance Attribute Details

#model_classObject (readonly)

Returns the value of attribute model_class.



18
19
20
# File 'lib/decidim/api/functions/component_finder_base.rb', line 18

def model_class
  @model_class
end

Instance Method Details

#call(component, args, _ctx) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/decidim/api/functions/component_finder_base.rb', line 24

def call(component, args, _ctx)
  @query = { component: }
  args.keys.each do |key|
    @query[key] = args[key]
  end
  query_scope.find_by(@query)
end

#query_scopeObject

By default, any model in its default scope Particular implementations may restrict this by adding additional constrains



35
36
37
# File 'lib/decidim/api/functions/component_finder_base.rb', line 35

def query_scope
  model_class
end