how to get a QueryRef without actually issuing the query, relying on future refetch calls? #2057
Replies: 1 comment
-
You are most likely looking for https://rxjs.dev/api/operators/switchMap, so you can do something that look like this pseudo-code: queryRefA = queryA.watch(args);
resultB = queryRefA.valueChanges.pipe(switchMap(resultA => {
return queryB.watch(resultA).valueChanges;
}))
resultB.subscribe(); // start by doing XHR for A, when A returns, starts XHR for B, and return result for B |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm struggling to figure out how to create an Observable that tracks the results to a query without actually issuing the query (because I don't know the arguments I want to use yet).
Here's what I'm trying to do. I'm generally quite new to Angular, so if I'm holding everything wrong, I'd love to hear.
Say I have a parent component and a child component. The child component wants to take in an
Observable
as an@Input({required: true})
. The parent component would like to bind the child input to one of the parent's fields - in particular an Observable that tracks the results of a query.Generally, I believe one does this by creating the respective observable in the parent's
ngOnInit()
. Withapollo-angular
, one gets an observable by creating aqueryRef
withqueryRef = queryB.watch(args)
. ThequeryRef
can be turned into an observable through itsvalueChanges
property. And one can then also callqueryRef.refetch(newArgs)
to re-issue the query and get new results.Now, my problem is that, at
ngOnInit
time, I don't yet have the arguments for myqueryB
. I first need anotherqueryA
to finish. So, the question is - is there any way I can get aqueryRef/Observable
that will be hooked to futurerefetch()
calls, but without actually issuing an initial query?Beta Was this translation helpful? Give feedback.
All reactions