@orpc/tanstack-query package provides deep TanStack Query (v5) integration for oRPC. It generates fully typed queryOptions, infiniteOptions, and mutationOptions from your router client.
Installation
createRouterUtils(client, options?)
Creates a router utils object from a client. The result mirrors the structure of your router, replacing each procedure with a ProcedureUtils object.
Options
Base path for all operations. Useful when creating utils for a sub-router.
Default options applied to all operations in the router utils.
ProcedureUtils
Each procedure in the router utils exposes the following methods:
.call(input, options?)
Directly calls the procedure client.
.queryKey(options?)
Generates a full matching TanStack Query key for this procedure.
.queryOptions(options?)
Generates useQuery / useSuspenseQuery compatible options.
.infiniteKey(options)
Generates a TanStack Query key for infinite queries.
.infiniteOptions(options)
Generates useInfiniteQuery / useSuspenseInfiniteQuery compatible options.
.mutationKey(options?)
Generates a TanStack Query mutation key.
.mutationOptions(options?)
Generates useMutation compatible options.
Streaming and event iterator utilities
For procedures that return event iterators, use the streamed or live query utilities..experimental_streamedKey(options?)
Generates a key for streamed queries.
.experimental_streamedOptions(options?)
Generates options for streaming queries. Each chunk is appended to the result array.
.experimental_liveKey(options?)
Generates a key for live queries.
.experimental_liveOptions(options?)
Generates options for live queries. Each chunk replaces the entire result (no accumulation).
RouterUtils type
The type of the value returned by createRouterUtils:
GeneralUtils
Every node in the router utils (both procedures and router groups) exposes a key() method for generating partial matching query keys — useful for cache invalidation and query filtering.
.key(options?)
Generates a partial matching key for actions like revalidating queries, checking mutation status, etc.
key() method is available at every level of the router utils tree, making it easy to invalidate broad or narrow sets of queries.
