AshDispatch.Resources.Notification (AshDispatch v0.5.1)

View Source

Reference documentation for Notification resources.

Important: This module is a placeholder. Consuming apps must create their own Notification resource using the Base module.

Creating Your Notification Resource

defmodule MyApp.Notifications.Notification do
  use AshDispatch.Resources.Notification.Base,
    repo: MyApp.Repo,
    domain: MyApp.Notifications,
    extensions: [AshTypescript.Resource]

  # Optional: TypeScript type generation
  typescript do
    type_name("Notification")
  end

  # Add your User relationship
  relationships do
    belongs_to :user, MyApp.Accounts.User do
      source_attribute :user_id
      destination_attribute :id
      allow_nil? false
      public? true
      define_attribute? false  # Base already defines user_id
    end
  end
end

Counter Broadcasting

The Base module includes counter broadcasting DSL (via AshDispatch.Resource). Configure counters for real-time notification counts:

counters do
  counter :unread_notifications,
    trigger_on: [:create, :mark_as_read, :mark_all_as_read],
    query_filter: [read: false],
    audience: :user,
    invalidates: ["notifications"]
end

Configuration

Configure your custom resource in your app:

config :ash_dispatch,
  notification_resource: MyApp.Notifications.Notification

See AshDispatch.Resources.Notification.Base for full documentation.