Skip to main content

Query Hook Migration

Objective

Move all read-side data fetching behind query hooks that use the shared key factory.

Rules

  • all reads belong in hooks/queries/
  • no page or component should call raw fetch for app data reads
  • every useQuery must use globalKeys or userKeys(userId)
  • user-scoped queries must be disabled when userId or other required auth context is missing

Migration Pattern

Before:
After:

Required Review Work

For each query hook:
  1. confirm whether the data is user-scoped or global
  2. replace inline keys with factory keys
  3. confirm enabled guards still prevent unauthenticated fetches
  4. update any in-file invalidation to use the same factory
  5. remove local key builder helpers

Domains To Migrate

Suggested grouping:
  • core: accounts, manual accounts, holdings, net worth, daily snapshots
  • transactions: unified, investment, manual, account-specific variants
  • assets/liabilities: properties, vehicles, physical assets, liabilities, other assets
  • crypto: wallets, crypto holdings, plaid crypto holdings, coinbase data
  • vault/chat/settings: vault folders/documents, chat sessions, user info, personal info, settings
  • remaining app domains: subscriptions, earnings, sync status, alerts, research, news, market data

Fetch Extraction Rule

If a page/component currently does this:
and the call is a read, move that logic into a new or existing file under hooks/queries/. Example naming:
  • hooks/queries/use-sync-status.ts
  • hooks/queries/use-research-sessions.ts
  • hooks/queries/use-account-refresh-status.ts

Acceptance Criteria

  • no raw read-side fetch calls remain in pages/components for app data
  • every query hook uses the shared factory
  • every user-scoped query is isolated by userId