Skip to main content
query() creates a reactive data-fetching primitive. Pass it a SDK method call and it returns reactive properties (data, loading, error) that auto-update in the DOM. It supports SSR data pre-fetching and integrates with the entity store for cross-component cache invalidation.

query()

Pass a generated SDK method call. The cache key and types are inferred automatically from the SDK:
SDK methods return a QueryDescriptor — an object that carries the fetch function, a deterministic cache key, and entity metadata. query() unwraps the Result for you: if the SDK call succeeds, data gets the value; if it fails, error gets the error. See the Generated SDK reference for details on how SDK methods and the Result type work.

Signature


QueryResult

The returned object has reactive properties that auto-update in the DOM — the compiler handles reactivity for you.
PropertyTypeDescription
dataT | undefinedResolved data, or undefined while loading
loadingbooleantrue during the initial fetch
revalidatingbooleantrue during background refetch (stale-while-revalidate)
errorE | undefinedError from the last failed fetch
idlebooleantrue when the query has never fetched (e.g. thunk returned null)
refetch()() => voidRe-execute the query (shows loading state)
revalidate()() => voidBackground refetch (keeps current data visible)
dispose()() => voidCancel the query and clean up subscriptions
refetch() resets data to undefined and shows loading state. revalidate() keeps the current data visible while fetching fresh data in the background (stale-while-revalidate pattern).

QueryOptions

OptionTypeDefaultDescription
keystringCache key (auto-inferred from SDK descriptors)
initialDataTInitial data to use before the first fetch completes
debouncenumberDebounce interval in ms before executing
cacheCacheStore<T>Custom cache store
ssrTimeoutnumberMax time to wait for the query during SSR (ms)
refetchIntervalnumber | false | (data, iteration) => number | falsefalsePolling interval in ms, or a function for dynamic intervals

invalidate()

Force all queries with a matching key to refetch.

Signature


SSR support

Queries execute during SSR automatically. The server waits for queries to resolve (up to ssrTimeout), serializes the data, and the client hydrates without re-fetching.

Types