T
tRPC

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

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

KKranga11/28/2022
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.
UUUnknown User11/28/2022
Message Not Public
Sign In & Join Server To View
KKranga11/28/2022
I get the same error due to circular references router=>caller=>router

Looking for more? Join the community!

T
tRPC

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

Join Server