Devben
Devben11mo ago

useQuery throwing errors

Argument of type 'FunctionReference<"mutation", "public", { bio: string; stack: string; links: string; }, null>' is not assignable to parameter of type 'FunctionReference<"query">'. Type '"mutation"' is not assignable to type '"query"'.
7 Replies
Devben
DevbenOP11mo ago
my schema.ts code: import { defineSchema, defineTable } from "convex/server"; import { v } from "convex/values"; export default defineSchema({ messages: defineTable({ body: v.string(), user: v.id("users"), }), onboard: defineTable({ bio: v.string(), stack: v.string(), links: v.string() }), users: defineTable({ pictureUrl: v.string(), name: v.string(), tokenIdentifier: v.string(), }).index("by_token", ["tokenIdentifier"]), }); onboard.ts code: import { v } from "convex/values"; import { mutation } from "./_generated/server"; export const setOnboarding = mutation({ args: { bio: v.string(), stack: v.string(), links: v.string(), }, handler: async (ctx, args) => { await ctx.db.insert("onboard", { bio: args.bio, stack: args.stack, links: args.links, }); }, }); My frontend code: const setOnboarding = useQuery(api.onboard.setOnboarding) The erros: [{ "resource": "/d:/letscollab/components/verifyForm.tsx", "owner": "typescript", "code": "2345", "severity": 8, "message": "Argument of type 'FunctionReference<"mutation", "public", { bio: string; stack: string; links: string; }, null>' is not assignable to parameter of type 'FunctionReference<"query">'.\n Type '"mutation"' is not assignable to type '"query"'.", "source": "ts", "startLineNumber": 16, "startColumn": 34, "endLineNumber": 16, "endColumn": 59 }]
lee
lee11mo ago
it's a mutation so you want useMutation, not useQuery
Devben
DevbenOP11mo ago
Thanks brother no more errors thanks but can you please explaing why is usemutation and not usequery thanks
lee
lee11mo ago
useQuery is for queries (readonly, reactive data loading). useMutation is for mutations (read-write, imperative actions)
lee
lee11mo ago
Queries | Convex Developer Hub
Queries are the bread and butter of your backend API. They fetch data from the
lee
lee11mo ago
Mutations | Convex Developer Hub
Mutations insert, update and remove data from the database, check authentication
Devben
DevbenOP11mo ago
solved thanks

Did you find this page helpful?