Skip to content

Dependent queries are not working with tanstack query #5

Open
@Irutom

Description

@Irutom

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,
  });

Query

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"]}]}

https://tanstack.com/query/latest/docs/framework/react/guides/dependent-queries

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions