lukemorales / query-key-factory

A library for creating typesafe standardized query keys, useful for cache management in @tanstack/query
https://www.npmjs.com/package/@lukemorales/query-key-factory
MIT License
1.23k stars 32 forks source link

support for nested keys? #8

Closed Shajansheriff closed 2 years ago

Shajansheriff commented 2 years ago

This is just to initiate a discussion around supporting nested keys. @lukemorales have you seen trpc router examples https://trpc.io/docs/v9/merging-routers? It would be great if we could think about how to support nested and merging keys. Most of the time, people like to organise in a central location.

`

lukemorales commented 2 years ago

@Shajansheriff thanks for starting the discussion!

I think supporting nested keys is a natural evolution of the package, it will be a fun experiment with Typescript to make that happen.

I really liked the idea of merging the keys, and inspired by that I've got a similar API:

CleanShot 2022-08-30 at 19 27 45

It uses the default key a user provided to create the query scope to populate the fields on a single object. How does that sound to you?

lukemorales commented 2 years ago

I feel like providing both APIs (creating smaller scopes and merging into a single one, and creating a single huge factory) will be useful for cases that depend on how people like to structure their code.

I'm thinking createQueryKeys + createMergedQueryKeysFactory (name TBD) will serve people that like smaller files and slices of objects that they can then merge into a big one, and the next step would be to create a createQueryKeysFactory that creates a single huge object