Basscar1408
Basscar1408
CCConvex Community
Created by Basscar1408 on 10/17/2024 in #support-community
Using Convex query gives Cannot find module '@/convex/_generated/api'
I resolved this, by reafactoring the logic and removing the promptId from the prompt table
10 replies
CCConvex Community
Created by Basscar1408 on 10/17/2024 in #support-community
Using Convex query gives Cannot find module '@/convex/_generated/api'
Im also now trying to use it in a mutation and im getting this error
convex/scores.ts:16:39 - error TS2339: Property 'prompts' does not exist on type '{ auth: { signIn: FunctionReference<"action", "public", { provider?: string | undefined; verifier?: string | undefined; refreshToken?: string | undefined; params?: any; calledBy?: string | undefined; }, { ...; }, string | undefined>; signOut: FunctionReference<...>; }; ... 7 more ...; playerresults: { ...; }; }'.

16 const activePrompt = useQuery(api.prompts.getActivePrompt);
~~~~~~~

Found 1 error in convex/scores.ts:16
convex/scores.ts:16:39 - error TS2339: Property 'prompts' does not exist on type '{ auth: { signIn: FunctionReference<"action", "public", { provider?: string | undefined; verifier?: string | undefined; refreshToken?: string | undefined; params?: any; calledBy?: string | undefined; }, { ...; }, string | undefined>; signOut: FunctionReference<...>; }; ... 7 more ...; playerresults: { ...; }; }'.

16 const activePrompt = useQuery(api.prompts.getActivePrompt);
~~~~~~~

Found 1 error in convex/scores.ts:16
this is the mutation
import { v } from "convex/values";
import { internalMutation } from "./_generated/server";
import { useQuery } from "convex/react";
import { api } from "./_generated/api";

export const incrementScore = internalMutation({
args: {
modelId: v.string(),
},
handler: async (ctx, args) => {
const score = await ctx.db
.query("scores")
.filter((q) => q.eq(q.field("modelId"), args.modelId))
.first();

const activePrompt = useQuery(api.prompts.getActivePrompt);
console.log(activePrompt);

if (!score && activePrompt) {
await ctx.db.insert("scores", {
modelId: args.modelId,
promptId: activePrompt?.promptId,
score: 1,
});
} else if (score) {
await ctx.db.patch(score._id, {
score: 1,
});
}
},
});
import { v } from "convex/values";
import { internalMutation } from "./_generated/server";
import { useQuery } from "convex/react";
import { api } from "./_generated/api";

export const incrementScore = internalMutation({
args: {
modelId: v.string(),
},
handler: async (ctx, args) => {
const score = await ctx.db
.query("scores")
.filter((q) => q.eq(q.field("modelId"), args.modelId))
.first();

const activePrompt = useQuery(api.prompts.getActivePrompt);
console.log(activePrompt);

if (!score && activePrompt) {
await ctx.db.insert("scores", {
modelId: args.modelId,
promptId: activePrompt?.promptId,
score: 1,
});
} else if (score) {
await ctx.db.patch(score._id, {
score: 1,
});
}
},
});
and the schema
prompts: defineTable({
promptId: v.id("prompts"),
prompt: v.string(),
isActive: v.boolean(),
}).index("by_active", ["isActive"]),
});
prompts: defineTable({
promptId: v.id("prompts"),
prompt: v.string(),
isActive: v.boolean(),
}).index("by_active", ["isActive"]),
});
10 replies