Skip to the content

liveState

Helpers for a Relay resolver marked @live. @live is a resolver docblock, not a transport. The compiler configuration stays in your app. A payload normalized into the store still needs a global id.
Relay

When to use

Use when
  • a resolver returns a LiveState;
  • one GraphQL subscription should feed that state;
  • several @live fields should recompute once for the same change.
Avoid when
  • you want a server live-query protocol — this package does not speak one;
  • the query should refetch on a timer — that is @client_polling on CreateRelayEnvironment;
  • the field only sets metadata.live.config_id — that is not a push channel here.

Usage

import { subscriptionLiveState, suspenseSentinel } from '@apollion-dsi/relay/liveState';

const ticks = subscriptionLiveState({
  environment,
  subscription: TickSubscription,
  variables: { id },
});

const value = ticks.read();
const waiting = value === suspenseSentinel();

Import the same functions from @apollion-dsi/relay. The subscription starts with the first listener.

API

Export
Use
liveState(read, subscribe)
LiveState that notifies only when Object.is says the value changed
batchLiveStateUpdates(environment, fn)
runs fn inside the store batch when the store provides one
subscriptionLiveState({ environment, subscription, variables })
suspenseSentinel() until the first payload, then batched notifications; disposes when the last listener leaves
suspenseSentinel
re-export; the value read() returns before the first payload
LiveState
re-exported type
Scrolls sideways inside the table. The page does not.

See also