Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: getQueryKey server side #5493

Open
1 task
FranciscoCaetano88 opened this issue Feb 18, 2024 · 0 comments
Open
1 task

feat: getQueryKey server side #5493

FranciscoCaetano88 opened this issue Feb 18, 2024 · 0 comments

Comments

@FranciscoCaetano88
Copy link

FranciscoCaetano88 commented Feb 18, 2024

Describe the feature you'd like to request

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.

Describe the solution you'd like to see

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;

}`

Describe alternate solutions

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.

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant