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: (customizable) query key prefix #5251

Open
1 task done
timvandam opened this issue Jan 1, 2024 · 2 comments
Open
1 task done

feat: (customizable) query key prefix #5251

timvandam opened this issue Jan 1, 2024 · 2 comments

Comments

@timvandam
Copy link

timvandam commented Jan 1, 2024

Describe the feature you'd like to request

I would like trpc query keys to have some prefix (e.g. 'trpc') to make it easy to identify them when setting up a QueryClient. This is useful when the query client is not only used for trpc. A simple example:

        queryClient.setMutationDefaults(getQueryKey(trpc), {
            onSuccess: () => {
                trpcUtils.invalidate();
            },
        });

Currently, getQueryKey(trpc) simply returns [], meaning that any mutation would invalidate all react-query queries, not only trpc queries. Being able to specify a prefix (or just having a prefix in general) would make it return [prefix], making it possible to distinguish between trpc queries and other queries.

I'm sure there are other (perhaps more useful) use cases than this

Describe the solution you'd like to see

Either a built in trpc prefix for all query keys, or a way to specify a prefix

Describe alternate solutions

I think the only real solution at the moment is to manually pass a react query context to trpc, such that you have an isolated query client (haven't tested this, seems like a reasonable idea)

Alternatively you could also create a wrapper route that serves as the root route to make sure that the query key is not empty

Additional information

If this is something that would be merged I am willing to give implementing this a shot

👨‍👧‍👦 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
@acatzk
Copy link

acatzk commented Feb 6, 2024

I also have the same question how to specify a query key in each query

@divmgl
Copy link

divmgl commented Mar 8, 2024

I need to specify a custom query key and I'm unable to. This means I can't use TanStack Query's hierarchical invalidations.

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

3 participants