Module: Decidim::QueryExtensions
- Defined in:
- lib/decidim/query_extensions.rb
Overview
This module’s job is to extend the API with custom fields related to decidim-core.
Class Method Summary collapse
-
.included(type) ⇒ Object
Public: Extends a type with
decidim-core‘s fields.
Instance Method Summary collapse
- #component(id: {}) ⇒ Object
- #decidim ⇒ Object
- #organization ⇒ Object
- #session ⇒ Object
- #user(id: nil, nickname: nil) ⇒ Object
- #users(filter: {}, order: {}) ⇒ Object
Class Method Details
.included(type) ⇒ Object
Public: Extends a type with decidim-core‘s fields.
type - A GraphQL::BaseType to extend.
Returns nothing.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/decidim/query_extensions.rb', line 12 def self.included(type) type.field :component, Decidim::Core::ComponentInterface, null: true do description "Lists the components this space contains." argument :id, GraphQL::Types::ID, required: true, description: "The ID of the component to be found" end type.field :session, Core::SessionType, description: "Return's information about the logged in user", null: true type.field :decidim, Core::DecidimType, "Decidim's framework properties.", null: true type.field :organization, Core::OrganizationType, "The current organization", null: true type.field :user, type: Core::AuthorInterface, null: true, description: "A participant (user or group) in the current organization" do argument :id, GraphQL::Types::ID, "The ID of the participant", required: false argument :nickname, GraphQL::Types::String, "The @nickname of the participant", required: false end type.field :users, type: [Core::AuthorInterface], null: true, description: "The participants (users or groups) for the current organization" do argument :order, Decidim::Core::UserEntityInputSort, "Provides several methods to order the results", required: false argument :filter, Decidim::Core::UserEntityInputFilter, "Provides several methods to filter the results", required: false end end |
Instance Method Details
#component(id: {}) ⇒ Object
39 40 41 42 |
# File 'lib/decidim/query_extensions.rb', line 39 def component(id: {}) component = Decidim::Component.published.find_by(id:) component&.organization == context[:current_organization] ? component : nil end |
#decidim ⇒ Object
48 49 50 |
# File 'lib/decidim/query_extensions.rb', line 48 def decidim Decidim end |
#organization ⇒ Object
52 53 54 |
# File 'lib/decidim/query_extensions.rb', line 52 def organization context[:current_organization] end |
#session ⇒ Object
44 45 46 |
# File 'lib/decidim/query_extensions.rb', line 44 def session context[:current_user] end |
#user(id: nil, nickname: nil) ⇒ Object
56 57 58 |
# File 'lib/decidim/query_extensions.rb', line 56 def user(id: nil, nickname: nil) Core::UserEntityFinder.new.call(object, { id:, nickname: }, context) end |
#users(filter: {}, order: {}) ⇒ Object
60 61 62 |
# File 'lib/decidim/query_extensions.rb', line 60 def users(filter: {}, order: {}) Core::UserEntityList.new.call(object, { filter:, order: }, context) end |