Live updates

Open a WebSocket to the same host as the API and Fóir tells your application when a record changes. Each event carries the id of what changed, and the SDK can turn that into an update to your query cache.

One socket, the same key

Subscriptions use the graphql-ws protocol on the API's own host, with the same API key as your queries and mutations. Credentials are sent when the connection opens: the key, and the access token of a signed-in user when there is one. A socket holds up to 32 live subscriptions.

What you can subscribe to

recordChanged reports changes to the records of one model. Other subscriptions cover the caller's own notifications, background job progress and the run of a single operation. Watching a model needs the same read permission as reading it, and on a model whose records are private to each user the stream is filtered to the caller's own records.

Events carry ids

A record event names the action (created, updated, published, unpublished or deleted), the record's id and its model. It identifies what changed and leaves the content out, so you read the record through the normal API. Each event also has a sequence number, per project and in commit order. Pass the highest one you have applied when you subscribe and the server replays what you missed from its durable log before it continues live.

The SDK's subscription client

The typed SDK gives each model an onChange method that returns a handle for unsubscribing. It opens the socket on the first subscription and closes it when the last one ends. If the connection drops, it reconnects with exponential backoff and re-sends the live subscriptions.

The live module

@foir/sdk/live connects the change stream to your query cache, and has a React binding. An edit refetches only the queries that held that record, a delete is applied in memory, and a create is reported as a count. You opt in per model.

Read the detail

The subscriptions guide covers the endpoint, each subscription and its event fields, and the live module.