Query caching with TanStack Query
Derive native query and mutation options from Service contracts without adding a wrapper hook layer.
Own one cache per identity
The optional adapter supplies a native QueryClient and typed options. Use native React or Octane query hooks and providers; Smoothie does not replace them.
import { createClient } from "@smoothie-framework/service/client";
import { createServiceQueryScope } from "@smoothie-framework/service-tanstack-query";
import { ReadStatus } from "../../shared/contracts";
const data = createServiceQueryScope({
client: createClient({ baseUrl: window.location.origin }),
scopeKey: ["public-status"],
});
const statusQuery = data.queryOptions(ReadStatus);
// Use statusQuery and data.queryClient with native query hooks/providers.
// Dispose with the owning session: data.dispose();Authenticated browsers own one scope per verified session; server consumers own one per request. scopeKey partitions cache identity, not authorization. Request-specific headers require an explicit public cache identity.
Select invalidation deliberately
mutationOptions accepts write contracts. After success, use data.refresh with the affected read options. Relationships, invalidation and UI feedback remain application-owned.
Mutations do not retry or queue offline; query retries also default to false. dispose cancels reads and prevents subsequent adapter calls, but cannot undo a write already sent. Never share one global server cache between users.
SSR cache transfer remains unqualified. Native query observers and providers retain their own lifetimes.