viniV
Convex Community13mo ago
33 replies
vini

Cannot solve "Convex functions should not directly call other Convex functions"

I searched, asked AI and tried to create helper functions but I can't get rid of this warn, it seems to be happening in my
Promise.all()
because I get a lot of logs.
My helper functions:
// convex/models/routes.ts

import { geospatial } from "@/convex";
import { internal } from "@/convex/_generated/api";
import { Id } from "@/convex/_generated/dataModel";
import { ActionCtx, MutationCtx } from "@/convex/_generated/server";
import schema from "@/convex/schema";
import { Infer } from "convex/values";

export async function insertRoute(
  ctx: MutationCtx,
  data: Infer<typeof schema.tables.routes.validator>,
): Promise<Id<"routes">> {
  return await ctx.db.insert("routes", { ...data });
}

export async function insertGeospatialPoint(
  ctx: MutationCtx,
  routeId: Id<"routes">,
  point: {
    latitude: number;
    longitude: number;
  },
) {
  return await geospatial.insert(
    ctx,
    routeId,
    {
      latitude: point.latitude,
      longitude: point.longitude,
    },
    {},
  );
}

// NEW FUNCTION
export async function insertManyGeospatialPoints(
  ctx: ActionCtx,
  routeId: Id<"routes">,
  points: {
    latitude: number;
    longitude: number;
  }[],
) {
  const promises = points.map((point) =>
    ctx.runMutation(internal.routes.insertGeospatialPointMutation, {
      routeId,
      point,
    }),
  );
  return await Promise.all(promises);
}


Rest of code is in the next comment because of Discord limit.
Was this page helpful?