anmot.
anmot.4mo ago

Dependent queries not working with tanstack query

Convex query is executed even if the enabled condition is not met.
const { fetchStatus, data: ordersResponse, isError, isPending: isOrderPending, isSuccess } = useQuery({
...convexQuery(api.orders.getOrdersByCartIds, { cartDocIds: cartDocIds ?? [], fetchProducts: true }),
enabled: !!cartDocIds?.length,
});
const { fetchStatus, data: ordersResponse, isError, isPending: isOrderPending, isSuccess } = useQuery({
...convexQuery(api.orders.getOrdersByCartIds, { cartDocIds: cartDocIds ?? [], fetchProducts: true }),
enabled: !!cartDocIds?.length,
});
Query
export const getOrdersByCartIds = zQuery({
args: {
cartDocIds: z.array(zid(CollectionNameEnum.enum.shopping_carts)).min(1),
fetchProducts: z.boolean().optional(),
},
...
export const getOrdersByCartIds = zQuery({
args: {
cartDocIds: z.array(zid(CollectionNameEnum.enum.shopping_carts)).min(1),
fetchProducts: z.boolean().optional(),
},
...
Below is the error
Uncaught ConvexError: {"ZodError":[{"code":"too_small","minimum":1,"type":"array","inclusive":true,"exact":false,"message":"Array must contain at least 1 element(s)","path":["cartDocIds"]}]}
Uncaught ConvexError: {"ZodError":[{"code":"too_small","minimum":1,"type":"array","inclusive":true,"exact":false,"message":"Array must contain at least 1 element(s)","path":["cartDocIds"]}]}
https://tanstack.com/query/latest/docs/framework/react/guides/dependent-queries
4 Replies
jamwt
jamwt4mo ago
pinging @ballingt , our tanstack expert
ballingt
ballingt4mo ago
@anmot. could you file an issue in https://github.com/get-convex/convex-react-query/issues? That makes sense, that's not one of the props we're passing through.
anmot.
anmot.OP4mo ago
Thanks for looking into this. Filed an issue - https://github.com/get-convex/convex-react-query/issues/5
ballingt
ballingt4mo ago
If you run into anything else @anmot. let us know, I'm getting back to this now that TanStack Start alpha is getting closer so it's a good time to make changes I'll look at this one tonight

Did you find this page helpful?