connectrpc / connect-query-es

TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers.
https://connectrpc.com/docs/web/query/getting-started
Apache License 2.0
218 stars 14 forks source link

Add API to allow permissive query keys #375

Open paul-sachs opened 3 months ago

paul-sachs commented 3 months ago

As of version 1.4.1, query keys are always generated with their default values populated. While this works really well for preventing duplicate queries, it prevents some use cases of createConnectQueryKey, primarily when used along with queryClient.invalidateQueries. See slack thread.

We should expose a standardized way of creating permissive keys that allow more generalized matching where we want to match multiple queries.

errorhandler commented 1 month ago

Is there any plans to add this in the short term? We've been holding off updating and I'm evaluating if we should make our own little function for the main use case we have: invalidate all instances of a particular RPC.

timostamm commented 1 month ago

Hey Joe, we'll update the function in v2, and we're actively working on v2, so it shouldn't be too long 🙂

The main reason to cut a v2 is to support Protobuf-ES v2, so we don't plan on changing the connect-query API too much, but this is a good chance to improve createConnectQueryKey.

It should be feasible to support creating a key for an entire service, for an individual RPC, and for an RPC with a specific request payload.

BTW, in the interim, you can create a key to invalidate all requests for an RPC with:

const key = createConnectQueryKey(rpc).slice(0, 2);