Skip to Content
FeaturesAPI GenerationMigrating from the Old Client

Migrating from the Old Client

The TypeScript client used to come from a hey-api wrapper with SWR hooks and per-group API classes. It is now generated by Orval 8.48 into React Query v5 hooks, Zod schemas and MSW mocks, and runs on the small @djangocfg/api runtime. This page is for an app that still has code written against the old client.

What changed

OldNew
SWR hooks useXxx and SWR keysReact Query v5 hooks use<Op> and key factories get<Op>QueryKey
useXxxInfinite for every Paginated* listuse<Op>Infinite, only with the Target option infinite; spread drfPageParams
new API(url), per-group <group>Api singletonsplain operation functions: cryptoCoinsList(params, options)
helpers/auth.ts per treeone runtime, @djangocfg/api (auth, djangoFetch), shared by every tree
helpers/cfg.tsruntime/cfg.ts (CFG = { version, contract })
auth.setBaseUrl('') for a proxyNEXT_PUBLIC_API_PROXY_URL='', or configureApi({ apiUrl: '/apix' }); setBaseUrl is an alias of setApiOrigin
URL regex for sign-in endpointsflags from the spec: auth: 'none', skipAuthRefresh: true
a hand-written prefix rewrite for groups that skip the proxyTarget option direct_origin_tags (origin: 'direct')
ApiQueryProvider / createApiQueryClient from @djangocfg/api/queryremoved: BaseApp provides the QueryClient (queryClient prop to bring your own)
SWRConfig, the swr prop of BaseApp, the SWR realtime middlewareremoved: realtime invalidates React Query queries through the QueryCache
useTopicRefresh, isKeyForTopic, topicsInKey (@djangocfg/realtime)removed: an invalidated_by view’s query carries meta.realtimeTopics, and BaseApp refreshes it
APIError(status, statusText, response, url, message?)APIError(statusCode, response, url, message?, statusText?); isPermissionError is still 403 only, isAuthError is 401
NetworkError(message, url, originalError?)NetworkError(message, { cause }, url)

Steps for one app

  1. Upgrade django-cfg (2.4.105 or later) and every @djangocfg/* package (2.1.664 or later) together: make update.
  2. Regenerate: make gen, then make gen-check (stamp and schema drift). The type-check gate refuses a tree that does not compile.
  3. Remove SWR: imports, the swr dependency, SWRConfig, the swr prop of BaseApp.
  4. Add @tanstack/react-query as a direct dependency of every app that mounts BaseApp (layouts has it as a peer).
  5. Delete your own QueryClientProvider around BaseApp, or pass that client as queryClient. Delete any module-scope QueryClient and any client passed to a hook as its last argument.
  6. Replace each SWR hook with the generated hook, each SWR key with get<Op>QueryKey, each mutate(key) with queryClient.invalidateQueries({ queryKey }).
  7. Replace useTopicRefresh(key, refetch) with @invalidated_by on the view (the generated query then refreshes itself).
  8. Grep for auth.setBaseUrl, setApiKey, NEXT_PUBLIC_API_PROXY_URL and NEXT_PUBLIC_STATIC_BUILD, and check each against API origin modes. An empty proxy URL now means same-origin again.
  9. tsc --noEmit in every app, then check one page in a browser as a guest and signed in: a clean console, requests go to the API host, the profile loads.

What was intentionally not restored

These were dropped by design. Do not rebuild them in an app.

  • SWR hooks. One data layer: React Query. Two caches cannot invalidate each other, and realtime refresh watches only React Query.
  • Class facades (class API, <group>Api singletons, StorageAdapter classes). Plain functions tree-shake, and one store per page replaced the per-instance state.
  • Typed SSE stream generators (stream<Op>()). Streams are not ordinary REST operations; they live in dedicated adapters (the chat widget’s transport, for one), which spread auth.clientHeaders() into their request.
  • APILogger. It was never wired to requests. Request capture is @djangocfg/devtools, auth events go to the store trace (window.__cfgAuth), and schema drift to zod-validation-error events.

Behaviour you may notice

  • A schema miss no longer breaks a page: it is reported and the data returned. Pass validation: 'strict' where you relied on a throw.
  • An aborted request rejects with the AbortError itself, not a NetworkError.
  • A refresh that fails on the network keeps the user signed in; only a refused refresh ends the session.
  • Sessions are shared across tabs and across every entry of @djangocfg/api in the page.
Last updated on