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
| Old | New |
|---|---|
SWR hooks useXxx and SWR keys | React Query v5 hooks use<Op> and key factories get<Op>QueryKey |
useXxxInfinite for every Paginated* list | use<Op>Infinite, only with the Target option infinite; spread drfPageParams |
new API(url), per-group <group>Api singletons | plain operation functions: cryptoCoinsList(params, options) |
helpers/auth.ts per tree | one runtime, @djangocfg/api (auth, djangoFetch), shared by every tree |
helpers/cfg.ts | runtime/cfg.ts (CFG = { version, contract }) |
auth.setBaseUrl('') for a proxy | NEXT_PUBLIC_API_PROXY_URL='', or configureApi({ apiUrl: '/apix' }); setBaseUrl is an alias of setApiOrigin |
| URL regex for sign-in endpoints | flags from the spec: auth: 'none', skipAuthRefresh: true |
| a hand-written prefix rewrite for groups that skip the proxy | Target option direct_origin_tags (origin: 'direct') |
ApiQueryProvider / createApiQueryClient from @djangocfg/api/query | removed: BaseApp provides the QueryClient (queryClient prop to bring your own) |
SWRConfig, the swr prop of BaseApp, the SWR realtime middleware | removed: 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
- Upgrade django-cfg (2.4.105 or later) and every
@djangocfg/*package (2.1.664 or later) together:make update. - Regenerate:
make gen, thenmake gen-check(stamp and schema drift). The type-check gate refuses a tree that does not compile. - Remove SWR: imports, the
swrdependency,SWRConfig, theswrprop ofBaseApp. - Add
@tanstack/react-queryas a direct dependency of every app that mountsBaseApp(layouts has it as a peer). - Delete your own
QueryClientProvideraroundBaseApp, or pass that client asqueryClient. Delete any module-scope QueryClient and any client passed to a hook as its last argument. - Replace each SWR hook with the generated hook, each SWR key with
get<Op>QueryKey, eachmutate(key)withqueryClient.invalidateQueries({ queryKey }). - Replace
useTopicRefresh(key, refetch)with@invalidated_byon the view (the generated query then refreshes itself). - Grep for
auth.setBaseUrl,setApiKey,NEXT_PUBLIC_API_PROXY_URLandNEXT_PUBLIC_STATIC_BUILD, and check each against API origin modes. An empty proxy URL now means same-origin again. tsc --noEmitin 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>Apisingletons,StorageAdapterclasses). 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 spreadauth.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 tozod-validation-errorevents.
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
AbortErroritself, not aNetworkError. - 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/apiin the page.
Last updated on