Skip to main content
A watched query stays current. useWatch in React and client.watch anywhere run a query and deliver its Result as it updates.
There is nothing to declare. Every read a query makes joins its read set, and the host runs the query again when a commit changes anything in that set.

What wakes a watch

  • A write to a fact the query read with ctx.get, or into a selection it read with ctx.list, ctx.page or ctx.count.
  • A change to the fact’s presence for a query that read it with ctx.has.
  • A change to the caller’s grants or to the guards the query’s entry depends on: authority is a read too, so a revoked grant reaches an open watch.
A change hidden above the watcher’s label never wakes it, and never reveals itself through a refusal. Each watcher sees exactly what its own frame may read.

One state at a time

Each query evaluation reads one committed version. A successful live answer carries the read’s version when the host supplies it. On an HTTP client, identical watches in the same frame share a stream when the query, arguments and seen match. Distinct watches use separate streams and catch up independently. After a checkout changes both a cart and its stock, a cart watch can show the new count while a stock watch still shows the earlier version. When values must agree, return them from one query and watch that answer. For example, read the cart count and stock in the same query and return both. That also gives time-sensitive reads the same evaluation instant. For separate one-off reads, you can select a retained version. Reconnect applies to each stream. A normal reconnect without a continuation uses the watch’s seen, if supplied. If the server furnished a resume token, reconnect presents the token from that stream’s last complete value to reopen its original read.

Your own writes

A watch catches up when a commit changes what its query read, including a commit by the caller. Pass the mutation’s version as seen to wait for an answer that includes that write. See Retries and read-your-writes.

Head only

The head is watched live. A watch in another world or at a valid instant (client.in(version), client.at(instant)) answers once, for the state it names. See Frames and trials.