CodeVetter · Repo Unpack · Data flow
reduxjs/redux-toolkit
Application arguments enter endpoint initiation and become serialized cache keys before request execution. Endpoint query functions translate arguments into transport inputs, while optional schemas and transforms shape results before Redux receives them. Hooks select cached state and manage subscriptions rather than owning the shared response cache. Rehydration and code generation introduce separate application-action and filesystem boundaries.
- defaultSerializeQueryArgs sorts plain-object keys, encodes bigint values, memoizes plain-object arguments in a WeakMap, and returns endpointName(serializedArgs); endpoint serializers may return a string directly or a value for default serialization.
- buildInitiateAnyQuery carries originalArgs, endpointName, queryCacheKey, subscription options, and forceRefetch into the thunk; its returned handle resolves from selected state and exposes abort, unwrap, refetch, unsubscribe, and subscription updates.
- executeRequest validates argSchema when enabled, then calls baseQuery(endpoint.query(arg), api, extraOptions) or endpoint.queryFn; successful data passes rawResponseSchema, transformResponse, and responseSchema in that order.
- fetchBaseQuery prepares headers, serializes JSON-compatible bodies and query parameters, joins the URL, and calls fetchFn with a Request; fetch, timeout, parsing, and HTTP-status failures return distinct error shapes with request/response metadata.
- Pending actions store request IDs, original arguments, and timestamps. Fulfilled writes reject mismatched request IDs unless upserting, then invoke endpoint merge or structural sharing; rejected writes likewise preserve the active request's ownership.
- React useQuery combines subscription and state hooks: argument changes unsubscribe the previous handle and dispatch initiate, while useQueryState derives a memoized endpoint selector and uses shallowEqual for subscription to Redux state.
- Optimistic updateQueryData turns a recipe into patches and inverse patches, exposes undo through patchQueryData, and applies patches to cached data; infinite requests instead accumulate aligned pages/pageParams arrays and trim them with maxPages.
- Rehydration moves application-supplied action payloads into completed query and fixed-key mutation cache entries. Separately, generateEndpoints resolves a schema path/URL, generates and formats TypeScript, then returns text or writes outputFile relative to cwd.