Module: Decidim::Core

Defined in:
lib/decidim/core/version.rb,
lib/decidim/core/api.rb,
lib/decidim/core/engine.rb,
app/types/decidim/core/date_type.rb,
app/types/decidim/core/user_type.rb,
lib/decidim/api/author_interface.rb,
app/types/decidim/core/metric_type.rb,
lib/decidim/api/scopable_interface.rb,
app/types/decidim/core/decidim_type.rb,
app/types/decidim/core/hashtag_type.rb,
app/types/decidim/core/session_type.rb,
lib/decidim/api/component_interface.rb,
app/types/decidim/core/category_type.rb,
lib/decidim/api/attachable_interface.rb,
lib/decidim/api/authorable_interface.rb,
app/types/decidim/core/component_type.rb,
app/types/decidim/core/date_time_type.rb,
app/types/decidim/core/scope_api_type.rb,
app/types/decidim/core/statistic_type.rb,
app/types/decidim/core/attachment_type.rb,
app/types/decidim/core/user_group_type.rb,
app/types/decidim/core/coordinates_type.rb,
lib/decidim/api/categorizable_interface.rb,
app/types/decidim/core/organization_type.rb,
app/resolvers/decidim/core/metric_resolver.rb,
app/types/decidim/core/metric_history_type.rb,
app/types/decidim/core/localized_string_type.rb,
app/types/decidim/core/translated_field_type.rb,
lib/decidim/api/participatory_space_interface.rb,
app/types/decidim/core/participatory_space_type.rb

Overview

This holds the decidim-core version.

Defined Under Namespace

Classes: Engine, MetricResolver

Constant Summary collapse

DateType =
GraphQL::ScalarType.define do
  name "Date"
  description "An ISO8601 date"

  coerce_input ->(value, _ctx) { Date.iso8601(value) }
  coerce_result ->(value, _ctx) { value.to_date.iso8601 }
end
UserType =

This type represents a User.

GraphQL::ObjectType.define do
  name "User"
  description "A user"

  interfaces [
    -> { Decidim::Core::AuthorInterface }
  ]

  field :name, !types.String, "The user's name"

  field :nickname, !types.String, "The user's nickname" do
    resolve ->(obj, _args, _ctx) { UserPresenter.new(obj).nickname }
  end

  field :avatarUrl, !types.String, "The user's avatar url" do
    resolve ->(obj, _args, _ctx) { UserPresenter.new(obj).avatar_url(:thumb) }
  end

  field :profilePath, !types.String, "The user's profile url" do
    resolve ->(obj, _args, _ctx) { UserPresenter.new(obj).profile_path }
  end

  field :organizationName, !types.String, "The user's organization name" do
    resolve ->(obj, _args, _ctx) { obj.organization.name }
  end

  field :deleted, !types.Boolean, "Whether the user's account has been deleted or not" do
    resolve ->(obj, _args, _ctx) { UserPresenter.new(obj).deleted? }
  end

  field :badge, !types.String, "A badge for the user group" do
    resolve ->(obj, _args, _ctx) { UserPresenter.new(obj).badge }
  end
end
AuthorInterface =

This interface represents an author who owns a resource.

GraphQL::InterfaceType.define do
  name "Author"
  description "An author"

  field :name, !types.String, "The author's name"
  field :nickname, !types.String, "The author's nickname"

  field :avatarUrl, !types.String, "The author's avatar url"
  field :profilePath, !types.String, "The author's profile path"
  field :badge, !types.String, "The author's badge icon"

  field :deleted, !types.Boolean, "Whether the author's account has been deleted or not"

  resolve_type ->(obj, _ctx) {
                 return Decidim::Core::UserType if obj.is_a? Decidim::User
                 return Decidim::Core::UserGroupType if obj.is_a? Decidim::UserGroup
               }
end
MetricType =
GraphQL::ObjectType.define do
  name "MetricType"
  description "Metric data"

  field :name, !types.String, "The name of the metric"
  field :count, !types.Int, "The last value of the metric"
  field :history, !types[MetricHistoryType], "The historic values for this metric"
end
ScopableInterface =

This interface represents a commentable object.

GraphQL::InterfaceType.define do
  name "ScopableInterface"
  description "An interface that can be used in scopable objects."

  field :scope, Decidim::Core::ScopeApiType, "The object's scope"
end
DecidimType =

This type represents a Decidim’s global property.

GraphQL::ObjectType.define do
  name "Decidim"
  description "Decidim's framework-related properties."

  field :version, !types.String, "The current decidim's version of this deployment." do
    resolve ->(obj, _args, _ctx) { obj.version }
  end

  field :applicationName, !types.String, "The current installation's name." do
    resolve ->(obj, _args, _ctx) { obj.application_name }
  end

  field :rubyVersion, !types.String, "The current ruby version" do
    resolve ->(_, _, _) { RUBY_VERSION }
  end
end
HashtagType =

This type represents a User.

GraphQL::ObjectType.define do
  name "HashtagType"
  description "hashtags list"

  field :name, !types.String, "The hashtag's name"
end
SessionType =

This type represents the current user session.

GraphQL::ObjectType.define do
  name "Session"
  description "The current session"

  field :user, UserType, "The current user" do
    resolve ->(obj, _args, _ctx) { obj }
  end

  field :verifiedUserGroups, !types[!UserGroupType], "The current user verified user groups" do
    resolve ->(obj, _args, _ctx) { Decidim::UserGroups::ManageableUserGroups.for(obj).verified }
  end
end
ComponentInterface =
GraphQL::InterfaceType.define do
  name "ComponentInterface"
  description "This interface is implemented by all components that belong into a Participatory Space"

  field :id, !types.ID, "The Component's unique ID"

  field :name, !TranslatedFieldType, "The name of this component."

  field :weight, !types.Int, "The weight of the component"

  field :participatorySpace, !ParticipatorySpaceType, "The participatory space in which this component belongs to.", property: :participatory_space

  resolve_type ->(obj, _ctx) { obj.manifest.query_type.constantize }
end
CategoryType =
GraphQL::ObjectType.define do
  name "Category"
  description "A category that can be applied to other resources."

  field :id, !types.ID
  field :name, !TranslatedFieldType, "The name of this category."

  field :subcategories, !types[Decidim::Core::CategoryType], "Subcategories of this category."
  field :parent, Decidim::Core::CategoryType, "This category's parent category."
end
AttachableInterface =

This interface represents a commentable object.

GraphQL::InterfaceType.define do
  name "AttachableInterface"
  description "An interface that can be used in objects with attachments"

  field :attachments, !types[Decidim::Core::AttachmentType], "This object's attachments"
end
AuthorableInterface =

This interface represents a commentable object.

GraphQL::InterfaceType.define do
  name "AuthorableInterface"
  description "An interface that can be used in authorable objects."

  field :author, Decidim::Core::AuthorInterface, "The resource author" do
    # can be an Authorable or a Coauthorable
    resolve ->(authorable, _, _) {
      if authorable.respond_to?(:normalized_author)
        authorable&.normalized_author
      elsif authorable.respond_to?(:creator_identity)
        authorable&.creator_identity
      end
    }
  end
end
ComponentType =
GraphQL::ObjectType.define do
  interfaces [-> { ComponentInterface }]

  name "Component"
  description "A base component with no particular specificities."
end
DateTimeType =
GraphQL::ScalarType.define do
  name "DateTime"
  description "An ISO8601 date with time"
  coerce_input ->(value, _ctx) { Time.iso8601(value) }
  coerce_result ->(value, _ctx) { value.to_time.iso8601 }
end
ScopeApiType =
GraphQL::ObjectType.define do
  name "Scope"
  description "A scope"

  field :id, !types.ID
  field :name, !TranslatedFieldType, "The name of this scope."

  field :children, !types[Decidim::Core::ScopeApiType], "Descendants of this scope"
  field :parent, Decidim::Core::ScopeApiType, "This scope's parent scope."
end
StatisticType =
GraphQL::ObjectType.define do
  name "Statistic"
  description "Represents a single statistic"

  field :name, !types.String, "The name of the statistic" do
    resolve ->(statistic, _args, _ctx) {
      statistic[0]
    }
  end

  field :value, !types.Int, "The actual value of the statistic" do
    resolve ->(statistic, _args, _ctx) {
      statistic[1]
    }
  end
end
AttachmentType =
GraphQL::ObjectType.define do
  name "Attachment"
  description "A file attachment"

  field :url, !types.String, "The url of this attachment"
  field :type, !types.String, "The type of this attachment", property: :file_type
  field :thumbnail, types.String, "A thumbnail of this attachment, if it's an image.", property: :thumbnail_url
end
UserGroupType =

This type represents a UserGroup

GraphQL::ObjectType.define do
  name "UserGroup"
  description "A user group"

  interfaces [
    -> { Decidim::Core::AuthorInterface }
  ]

  field :id, !types.ID, "The user group's id"

  field :name, !types.String, "The user group's name"

  field :nickname, !types.String, "The user group nickname" do
    resolve ->(obj, _args, _ctx) { UserGroupPresenter.new(obj).nickname }
  end

  field :avatarUrl, !types.String, "The user's avatar url" do
    resolve ->(obj, _args, _ctx) { UserGroupPresenter.new(obj).avatar_url }
  end

  field :profilePath, !types.String, "The user group's profile url" do
    resolve ->(obj, _args, _ctx) { UserGroupPresenter.new(obj).profile_path }
  end

  field :deleted, !types.Boolean, "Whether the user group's has been deleted or not" do
    resolve ->(obj, _args, _ctx) { UserGroupPresenter.new(obj).deleted? }
  end

  field :badge, !types.String, "A badge for the user group" do
    resolve ->(obj, _args, _ctx) { UserGroupPresenter.new(obj).badge }
  end
end
CoordinatesType =

This type represents a Decidim’s global property.

GraphQL::ObjectType.define do
  name "Coordinates"
  description "Physical coordinates for a location"

  field :latitude, !types.Float, "Latitude of this coordinate" do
    resolve ->(coordinates, _args, _ctx) { coordinates[0] }
  end

  field :longitude, !types.Float, "Longitude of this coordinate" do
    resolve ->(coordinates, _args, _ctx) { coordinates[1] }
  end
end
CategorizableInterface =

This interface represents a commentable object.

GraphQL::InterfaceType.define do
  name "CategorizableInterface"
  description "An interface that can be used in categorizable objects."

  field :category, !Decidim::Core::CategoryType, "The object's category"
end
OrganizationType =
GraphQL::ObjectType.define do
  name "Organization"
  description "The current organization"

  field :name, types.String, "The name of the current organization"

  field :stats do
    type types[Core::StatisticType]
    description "The statistics associated to this object"
    resolve ->(object, _args, _ctx) {
      Decidim.stats.with_context(object)
    }
  end
end
MetricHistoryType =
GraphQL::ObjectType.define do
  name "MetricHistory"

  field :key, !types.String, "The key value" do
    resolve ->(obj, _args, _ctx) { MetricObjectPresenter.new(obj).attr_date(0) }
  end

  field :value, !types.Int, "The value for each key" do
    resolve ->(obj, _args, _ctx) { MetricObjectPresenter.new(obj).attr_int(1) }
  end
end
LocalizedStringType =

This type represents a localized string in a single language.

GraphQL::ObjectType.define do
  name "LocalizedString"
  description "Represents a particular translation of a LocalizedStringType"

  field :locale, !types.String, "The standard locale of this translation."
  field :text, types.String, "The content of this translation."
end
TranslatedFieldType =

This type represents a translated field in multiple languages.

GraphQL::ObjectType.define do
  name "TranslatedField"
  description "A translated field"

  field :locales do
    type types[types.String]
    description "Lists all the locales in which this translation is available"
    resolve ->(obj, _args, _ctx) { obj.keys }
  end

  field :translations do
    type !types[LocalizedStringType]
    description "All the localized strings for this translation."

    argument :locales do
      type types[!types.String]
      description "A list of locales to scope the translations to."
    end

    resolve lambda { |obj, args, _ctx|
      translations = obj.stringify_keys
      translations = translations.slice(*args["locales"]) if args["locales"]

      translations.map { |locale, text| OpenStruct.new(locale: locale, text: text) }
    }
  end

  field :translation do
    type types.String
    description "Returns a single translation given a locale."
    argument :locale, !types.String, "A locale to search for"

    resolve lambda { |obj, args, _ctx|
      translations = obj.stringify_keys
      translations[args["locale"]]
    }
  end
end
ParticipatorySpaceInterface =
GraphQL::InterfaceType.define do
  name "ParticipatorySpaceInterface"
  description "The interface that all participatory spaces should implement."

  field :id, !types.ID, "The participatory space's unique ID"

  field :title, !TranslatedFieldType, "The name of this participatory space."

  field :type, !types.String do
    description "The participatory space class name. i.e. Decidim::ParticipatoryProcess"
    resolve ->(participatory_space, _args, _ctx) {
      participatory_space.class.name
    }
  end

  field :components, types[ComponentInterface] do
    description "Lists the components this space contains."

    resolve ->(participatory_space, _args, _ctx) {
              Decidim::Component.where(
                participatory_space: participatory_space
              ).published
            }
  end

  field :stats, types[Decidim::Core::StatisticType] do
    resolve ->(participatory_space, _args, _ctx) {
      published_components = Component.where(participatory_space: participatory_space).published

      stats = Decidim.component_manifests.map do |component_manifest|
        component_manifest.stats.with_context(published_components).map { |name, data| [name, data] }.flatten
      end

      stats.reject(&:empty?)
    }
  end

  resolve_type ->(obj, _ctx) { obj.manifest.query_type.constantize }
end
ParticipatorySpaceType =
GraphQL::ObjectType.define do
  interfaces [-> { ParticipatorySpaceInterface }]

  name "ParticipatorySpace"
  description "A participatory space"
end

Class Method Summary collapse

Class Method Details

.versionObject



6
7
8
# File 'lib/decidim/core/version.rb', line 6

def self.version
  "0.19.1"
end