Replies: 2 comments 7 replies
-
Currently not all the methods supports promise or observable. We wanted to add it based on usage. I guess we can add support for ensureQueryData. Do you want to create a PR? |
Beta Was this translation helpful? Give feedback.
-
@donbabbeo unless you're doing something like Streaming, SSE or Websockets i would just convert the get/post/put/etc request to a promise since they'll be resolved once the request is done, you still can do error handling and all that stuff in there - the only difference being that you have to convert it to a promise (with |
Beta Was this translation helpful? Give feedback.
-
I'm reading TkDodo's blog and stumble upon this post about ReactRouter and prefetching and decided to give it a shot in Angular.
The concept it's pretty simple: use the resolver function to fetch early to prevent loading the component at all in case of error and leveraging the cache of Tanstack Query to get the data in the component. This involve calling
ensureQueryData
on the queryClient to guarantee that the data exist on cache.I create a simplistic approach in this StackBlitz.
As you can see the "problem" is that queryClient is built to reason with promises and when you pass a promise as queryFn to
ensureQueryData
or similar methods it got resolved internally. This does not play well with queryFn when is an Observable: queryClient doesn't treat it and thus the return type ofensureQueryData
isPromise<Observable< T >>
instead ofPromise< T >
.Clearly the simple solution is avoid queryFn with observable and if we need to manipulate the observable stream we need to use
result$
from the query result. But i don't like the idea, i prefer dealing only with observable.Any idea if this could be adressed somehow?
Beta Was this translation helpful? Give feedback.
All reactions