Module subscription

Module subscription 

Source
Expand description

GraphQL subscriptions using PostgreSQL LISTEN/NOTIFY.

This module provides realtime data synchronization through GraphQL subscriptions, powered by PostgreSQL’s native LISTEN/NOTIFY mechanism.

§Architecture

┌──────────────┐   WebSocket   ┌──────────────┐   LISTEN/NOTIFY   ┌────────────┐
│   Client     │◀────────────▶│   Postrust   │◀────────────────▶│  PostgreSQL│
│  (Browser)   │              │   Server     │                   │  Database  │
└──────────────┘              └──────────────┘                   └────────────┘

§Usage

  1. Create notification triggers on your tables using broker::create_notify_trigger_sql
  2. Start the NotifyBroker to listen for database notifications
  3. Use GraphQL subscriptions to receive realtime updates

§Example

subscription {
  users {
    id
    name
    email
  }
}

Re-exports§

pub use broker::create_notify_trigger_sql;
pub use broker::drop_notify_trigger_sql;
pub use broker::table_channel_name;
pub use broker::BrokerError;
pub use broker::NotifyBroker;
pub use broker::PgNotification;

Modules§

broker
PostgreSQL NOTIFY message broker for GraphQL subscriptions.

Structs§

SubscriptionField
A subscription field in the GraphQL schema.
TableChangePayload
Payload structure for table change notifications.

Functions§

generate_subscription_fields
Generate subscription fields for all tables in the schema.