I'd like to have a way of getting/building a query key from a procedure or router from the server. The implementation of getQueryKey shouldn't be bound to the client only.
The following usecase describes a function where I get all the data from a dataset and populate the queryClient with each individual data as if they were fetched individually. Since I already have the dataset required I shouldn't be forced to refetch each individual data to populate the queryClient's cache:
`async function fetchSomething({ queryClient }: { queryClient: QueryClient }) {
const helpers = await createSSRHelper();
const somethingData = await helpers.something.getAllOfSomething.fetch({
withMoreStuff: true
});
somethingData.forEach((something) => {
const queryKey = getQueryKey(trpc.something.getSomethingById, {
somethingId: something.id,
withMoreStuff: true
});
queryClient.setQueryData(queryKey, something);
});
return somethingData;
}`
An alternate solution would be to fetch each data using the SSR Helper (causing unnecessary queries to a db or other services) or to input the querykey by hand in the setQueryData.
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too