withTelefunc() returns the same new QueryClient() instance:
All options and APIs continue to work as before
Any TanStack Query adapter works: React, Vue, Svelte, Solid
There isn't any other setup: Telefunc finds @telefunc/* packages in your package.json and auto-loads them.
Local vs global keys
After installing @telefunc/tanstack-query, keys prefixed with global: become special: they invalidate globally — every connected client with a matching query refetches.
All other keys remain normal (invalidate locally, i.e. current tab only).
How does it work? Under the hood, the global: key is sent to the server and then broadcast to every client using a query key that matches. Learn more at How it works.
queryKey: ['todos'] // local — current tab onlyqueryKey: ['global:todos', `user:${userId}`] // global — all clients with a matching query refetchqueryKey: ['global:documents', docId] // global
A key is global when its first element is a string starting with global:, for example:
['global:todos', `user:${userId}`] is global
['todos', 'global:x'] is local
Mutations
meta.invalidates
Use meta.invalidates on mutations to invalidate matching queries after the mutation succeeds.
The @telefunc/tanstack-query integration must access the return value of the telefunction call.
Server-side invalidation
For changes not triggered by a client mutation (e.g. background jobs, webhooks), you can use invalidate():
// Environment: serverimport { invalidate } from '@telefunc/tanstack-query/server'// e.g. a CMS publishes new contentinvalidate(['global:articles'])// a specific document was updatedinvalidate(['global:documents', docId])
invalidate() is for global keys only. (Local keys have no cross-client subscribers, so they wouldn't reach any client.)
Invalidation is prefix-based: invalidating ['global:documents'] matches ['global:documents', docId] too. This is the same behavior as TanStack Query's invalidateQueries().
How it works
Local keys
Query: normal (@telefunc/tanstack-query has no effect).