Feature by feature
Chapter 6 of 11
Actions, jobs and webhooks
External code, background jobs and webhooks run under the same caller rules and commit boundaries as your queries. Gatekeeper queries guard handlers and jobs commit alongside writes, while the change log feeds warehouses without polling.
Queries and live subscriptions keep state inside PostgreSQL, while production apps also send emails, run delayed tasks and sync analytics warehouses. Moving work outside a database query should not bypass caller policies or fire on rolled-back data.
In practice
An action runs a gatekeeper query under the caller’s identity before invoking external code. If Ben calls emailNote with the ID of Ada’s private note, PostgreSQL returns zero rows and Napalm responds with 403 nothing_found without waking the handler. When Ada calls emailNote on her note, the handler receives the permitted row and sends the email.
Actions and hosted handlers#
Pillar at work: Caller-bound
An action pairs a saved .edgeql query with handler code written in TypeScript, Python, Go, Rust or Dart. PostgreSQL executes the query first under the caller’s access policies, and Napalm invokes the handler only when at least one permitted row matches.
Gatekeeper query
PostgreSQL checks the paired query first and blocks unauthorized calls.
On-demand handlers
Handlers wake per call and hold no standing database password.
Because the gatekeeper query runs under global caller, unauthorized requests fail inside PostgreSQL before waking external code.
select Note { title, body }filter .id = <uuid>$noteWhen a handler needs to write results back, exchanging its call token yields a 60-second session scoped to the original caller. Place a matching file in handlers/ to run on Napalm’s serverless runtime, or point the action at your own HTTPS endpoint.
# handlers/emailNote.ts pairs with dbschema/queries/emailNote.edgeqlnapalm handlers deploy notesJobs and cron schedules#
Pillar at work: Commit-atomic
Enqueueing work on a separate broker from an HTTP handler can lose jobs on a crash or run jobs after a database rollback. In Napalm, background jobs are rows in ext::napalm::Job that commit in the same statement as your writes.
with note := (insert Note { owner := global caller, title := <str>$title, body := <str>$body }), reminder := (insert ext::napalm::Job { query := 'sendReminder', variables := <json>(note := <str>note.id), run_time := datetime_of_statement() + <duration>'24 hours', }),select note { id }Rolled-back transactions leave no job behind. When run_time arrives, the job executes under the caller’s identity and carries a stable job ID across retries so handlers can deduplicate outbound calls.
Transactional jobs
Job rows commit alongside your writes and run asynchronously as the original caller.
Recurring tasks without a user session, such as daily digests or rollups, run on cron schedules under a dedicated service key.
napalm schedules add notes sendDigest '0 8 * * *' --key <key-id>Commit notifications and webhooks#
External receivers watching changes to a type need no polling loop. Add a notify declaration on the schema type to emit an event whenever a transaction commits an insert, update or delete.
type Note { required owner: ext::auth::Identity; multi editors: ext::auth::Identity; required title: str; required body: str; # …search indexes and access policies notify note_changed after insert, update, delete;}Subscribed HTTPS endpoints receive an HMAC-signed ping containing the commit’s Napalm-Position bookmark as soon as the write commits. Rolled-back transactions and dry runs send nothing.
Reading the change log#
Pillar at work: Compiled
Every committed write appends to the branch’s ordered change log. From a terminal, napalm changes summarizes recent commits with an org token without exposing row values.
When a webhook ping wakes your sync worker, passing Napalm-Position as reach alongside the worker’s stored cursor guarantees the response includes the commit that triggered the ping, even when served by a read replica. Every row returned by GET /changes is filtered through the caller key’s select policies.
curl "https://notes.napalmdata.com/changes?since=2026-11-08T00:00:00Z&types=Note&limit=100" \ -H "Authorization: Bearer $NAPALM_KEY"Warehouse sync#
Issue a dedicated read-only service key so your analytics or lakehouse worker can pull permitted changes without write privileges.
napalm keys create notes --label warehouse --read-onlyAfter an initial table copy, the worker pages forward from its saved cursor as webhook pings arrive. Applying a page is idempotent by primary key, and if a worker stays offline longer than your branch’s log retention, a gap marker instructs it to run a fresh copy. Each JSON change item also records how the write arrived (http, mcp, job or schedule).
So far every record has belonged to an individual user. Multi-tenant apps add shared workspaces, role hierarchies, usage ledgers and shard roots.