#How to consume __generated inside of a monorepo

2 messages · Page 1 of 1 (latest)

terse berryBOT
#

Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.

    - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
    - Use [search.convex.dev](https://search.convex.dev) to search Docs, Stack, and Discord all at once.
    - Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
    - Avoid tagging staff unless specifically instructed.

    Thank you!
lost trellis
#

Here's my export code inside packages/backend/api.ts

import { convexQuery, useConvexMutation } from "@convex-dev/react-query";
import { useMutation, useQuery } from "@tanstack/react-query";
import { FunctionArgs, FunctionReference } from "convex/server";

export * from "./convex/_generated/api.js";
export * from "./convex/_generated/dataModel.js";
export * from "./convex/_generated/server.js";

export function useBackendQuery<
  ConvexQueryReference extends FunctionReference<"query">,
  Args extends FunctionArgs<ConvexQueryReference> | "skip" | undefined,
>(funcRef: ConvexQueryReference, queryArgs?: Args) {
  return useQuery(convexQuery(funcRef, queryArgs));
}

export function useBackendMutation<
  Mutation extends FunctionReference<"mutation">,
>(funcRef: Mutation) {
  return useMutation({
    mutationFn: useConvexMutation(funcRef),
  });
}