psteinroe / supabase-cache-helpers

A collection of framework specific Cache utilities for working with Supabase.
https://supabase-cache-helpers.vercel.app
MIT License
458 stars 26 forks source link

Allow wildcard usage #377

Closed lauri865 closed 2 months ago

lauri865 commented 7 months ago

There's benefits to using useQuery without granular updates from mutations (e.g. auto-serialized queryKeys for filtering, etc.).

I believe thus by making the no wildcard rule less strict, we could make the library more useful.

I would be fine if e.g. all wildcard queries would get invalidated upon a mutation to the underlying table or any relation.

Not using wildcard would just make mutations more granular. But it doesn't have to be so binary, does it? (lmk if I'm missing something)

A console.warn in development would be enough to inform the devs about wildcard use, but no need to throw errors.

(Talking from react-query perspective, not sure about SWC considerations)

psteinroe commented 7 months ago

I also have a use case where this should be allowed: head: true queries with count. I did not touch the code base for a while so it will take a while for me to go that deep again and figure out how we can allow wildcards.

lauri865 commented 7 months ago

Tried to understand the code flow, and this is what I pictured together:

A few problems:

Some thoughts:

Probably a lot I didn't understand in the code base. Wondering now if a fresh stab at this with a simpler model would make more sense at this point for us. As a developer, I want to achieve base case automated cache invalidation first, and then make things progressively better.

rohankm commented 7 months ago

I need the * selector also

jpsaccount commented 5 months ago

Same

adamwett commented 3 months ago

temporary fix:

export const queryFields = <T extends object>(): string => {
    return (Object.keys({} as { [K in keyof T]: T[K] })).join(',');
};