Re-architect Angular Query around Angular Resource before stable release #10788
Replies: 1 comment
-
|
Hello 👋 I have been playing around with my fork of Angular Query, where I added proper SSR with pending tasks and hydratation support, so I think I can give input into this. I believe this can be split into 2 areas of discussion: 1. Should the Angular adapter use the resource API internally?The resource API helps a lot to simplify async operations. The main thing that the query adapter does is not async operations, is the subscription to the query client to an specific query thought an observer. You can see that in the Solid adapter: the main usage for the async primitive it is not for handling a promise, it is for connecting the observer behaviour to Solid primitives. The 2 features those promitives provide are:
So given that it is possible to use other APIs to do the same, I don't see benefit of using the Resource API. The adapter can use specialized APIs offering the same feature set, without relying on weird workarounds (like how the Solid adapter manages the promise). 2. Should the snapshot have a resource field? How it should behave?Even if it doesn't use the Resource API internally, it can use the Resource Interface. The My impression is that For how to map things, the For signal forms, a plain I uploaded my fork with a
For the last point, I added the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I’d like to propose making Angular Resource part of the core implementation of
injectQuery.The Angular adapter is still experimental, and when it was created Angular did not yet have a first-party Resource API. Now Angular does, and newer Angular APIs are starting to compose around resources. Signal Forms async validation is a good example:
validateAsync()is resource-based, butinjectQuery()currently returns a TanStack-shaped signal object, not a resource.That makes TanStack Query feel slightly outside Angular’s current async model. It works well with signals and templates, but it does not plug cleanly into APIs that expect a
ResourceRef.Proposal
Architect
injectQueryaround Angular Resource internally:The public API could remain mostly the same:
But because the implementation is resource-based, the underlying resource could also be exposed:
This would let Angular-native APIs consume TanStack Query without custom glue:
Why this should be part of the architecture
Angular signals are the reactivity primitive. Angular Resource is the async primitive.
injectQuery()currently integrates with the former, but not really with the latter.The Solid adapter is a useful comparison: it keeps the Query API, but integrates with Solid’s native async primitive under the hood. Angular now has its own equivalent async primitive, so it seems worth considering the same direction before the Angular adapter stabilizes.
The goal is not to hide TanStack Query behind Resource. TanStack Query still has important semantics that Resource does not fully capture, like stale state, background refetching, invalidation, retries, paused fetches, placeholder data, cache metadata, and separate
status/fetchStatus.So the returned object could expose both layers:
Open questions
injectQuery()be resource-based internally?query.resource,query.asResource(), or something else?query.data()come fromresource.value(), or should both come from a shared observer snapshot?statusandfetchStatusmap to AngularResourceStatus?resource.reload()map toquery.refetch()?resource.set()andresource.update()map toqueryClient.setQueryData()?injectInfiniteQuery()follow the same model?Since the Angular adapter is still experimental, this feels like the right time to decide whether it should be resource-first internally before the API stabilizes.
Beta Was this translation helpful? Give feedback.
All reactions