Kranga
Kranga3y ago

Is it possible to call a query from another query defined in the same router?

Say I have some code like the following:
t.router({
compute_all: t.procedure
.query(async ({ctx, input})=>{
//Receives an array of computable objects and applies the transformation defined in compute_one
const result = await Promise.all(input.datasets.map(x=>/*SOMETHING_SHOULD_BE_HERE*/));
return result;
}),
compute_one: t.procedure
.query(async ({ctx, input})=>{
const result = '...';//Fetches data and does some transformation on it
return result;
})
})
t.router({
compute_all: t.procedure
.query(async ({ctx, input})=>{
//Receives an array of computable objects and applies the transformation defined in compute_one
const result = await Promise.all(input.datasets.map(x=>/*SOMETHING_SHOULD_BE_HERE*/));
return result;
}),
compute_one: t.procedure
.query(async ({ctx, input})=>{
const result = '...';//Fetches data and does some transformation on it
return result;
})
})
Is it posible to reuse the compute_one query logic within the compute_all query without extracting the common logic outside the router? I have tried doing it via instantiating a client using that same router and executing the query as usual from within the query but I get 'default' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. due to the router=>client=>router circular reference.
2 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kranga
KrangaOP3y ago
I get the same error due to circular references router=>caller=>router

Did you find this page helpful?