flybayer · GitHub

What do you want and why?

Currently you need to manually call refetch() or mutate() on a useQuery result after doing a mutation.

We should try to come up with a way to automatically invalidate queries so that most users don't have to think about it all.

I haven't spent a lot of time thinking about this, but here's a couple options.

Based on file structure

We could automatically invalidate queries at the same folder level of the mutation.

So with this file structure,

app/products/queries/getProduct.ts
app/products/queries/getProducts.ts
app/products/mutations/createProduct.ts
app/products/mutations/updateProduct.ts
app/products/mutations/deleteProduct.ts

Calling createProduct, updateProduct, or deleteProduct would invalidate the cache for getProduct and getProducts.

But the problem with this is that app/queries/getDisplayProducts.ts would not be invalidated even thought it is also affected. But maybe this is still worth it if it solves the 80% use case.

Via Some Type of Introspection Magic

Maybe it's possible for us to compute the entire data graph at build time using a combination of the Prisma DMMF and Typescript? If possible, this would be amazing because we could accurately invalidate all queries anywhere in the app.

I think this would only work with Prisma, so we should still have some other fallback method for Blitz apps without Prisma.

On Route Change

Something else that's a possibility is busting the cache on route change, but that still requires you to think about it.

I'm super keen to hear anyone's ideas on this!

Read the original on github.com ↗