Replies: 10 comments 13 replies
-
hmm, is it so wrong to use the queryKey for that? I mean, maybe not by attaching a
but yeah, I can also get behind the idea of a One problem might be getting the typings right. We'd probably want to allow anything on the context, or at least any object, so it would be typed as
here, |
Beta Was this translation helpful? Give feedback.
-
I would prefer not to include that kind of information on my cache, it has nothing to do with my back-end structure, nor with the query itself -- it's only related to persistence. I think it's a totally separated concern which should not be mixed with different things. I believe we should indeed type |
Beta Was this translation helpful? Give feedback.
-
I've been taking a look at the code before taking any action, and it looks like simply adding meta?: Record<string, unknown> To the However, the path to the query.options.meta I'd like to drop the
It looks like the trade-off is not worth it, but that's not my library and I'd like your opinion first. 😄 Also, I saw we have an option called I don't think it would be a replacement for What do you think about it? Thanks! |
Beta Was this translation helpful? Give feedback.
-
PR ready on #2818. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the addition of the I wanted to strongly type the field in a project I'm working on. Currently, as interface Meta {
persist?: boolean;
}
declare module '@tanstack/react-query' {
interface QueryMeta extends Meta {}
} I added a PR that would allow this type of override here: #4253 |
Beta Was this translation helpful? Give feedback.
-
Sorry to open an old issue. Any way around this? |
Beta Was this translation helpful? Give feedback.
-
Using |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
For those of us currently stuck on v4, what's the best way to gain typed meta on both queries and mutations? |
Beta Was this translation helpful? Give feedback.
-
Mostly an academic question / I'm not advocating any pattern: Since Being that the global QueryCache callbacks only fire once, what is the behavior if a query is used in multiple components with different metas per instance? I'm assuming that the last-invoked query's meta wins, or something along those lines? |
Beta Was this translation helpful? Give feedback.
-
For a lot of use cases, it's very useful to have some way of passing metadata to the query options, so it can be accessed in some places. My main use case, and one I cannot work around right now without some hacking with the query key, is the following:
I'm persisting the data using the
persistQueryClient
. That's working great, however there are some queries I do not want to persist (like search results, for example). The only way I found right now would be to create a property on the query key and then checking if this property exists insideshouldDehydrateQuery
. If it does, ignore that query and don't persist it.That's the code I have right now: https://codesandbox.io/s/pedantic-agnesi-71dmf
The idea and proposed API, would be to include a property called
meta
orcontext
(likeapollo-client
has), which can be accessed elsewhere as needed. Example:And then, for example, you can look for the
meta
property onshouldDehydrateQuery
:That's somewhat related to #2286. This is a very common pattern on the
apollo-client
world as seen here and explained in detail on this article.I'm willing to implement that if I get the green light. I think it's super useful in a variety of cases and should definitely be implemented.
Beta Was this translation helpful? Give feedback.
All reactions