ŠtosdenferŠ
Convex Community4mo ago
16 replies
Štosdenfer

Issues with multiple repo api generation

🪲Bug Report
I'm having issues generating an API to use in another repository.

It is too late for me now to switch to monorepo, that's maybe something for the future, but right now launch is near and I would like to get it working with how it is.

The generated API file gives a lot of "any" errors. I don't mind fixing this manually, but I would need some guidance because I can't figure out what's supposed to go where.

Here are some snippets
// part of generated api file
export type PublicApiType = {
  priceHistory: {
    addPrice: FunctionReference<
      "mutation",
      "public",
      { price: number; setBy: string },
      any
    >;
    getLatestPrice: FunctionReference<"query", "public", any, any>;
  };
}


// priceHistory.ts
import { v } from "convex/values";
import { mutation, query } from "./_generated/server";

export const addPrice = mutation({
  args: {
    price: v.number(),
    setBy: v.string(),
  },
  handler: async (ctx, args) => {
    // check auth
    const identity = await ctx.auth.getUserIdentity();
    if (identity === null) {
      throw new Error("Not authenticated");
    }

    await ctx.db.insert("price_history", {
      ...args,
    });
  },
});

export const getLatestPrice = query({
  handler: async (ctx) => {
    return await ctx.db.query("price_history").order("desc").first();
  },
});


// part of schema
export default defineSchema({
  price_history: defineTable({
    price: v.number(),
    setBy: v.string(),
  }),
)}
Was this page helpful?