Struggling using convex mutations
Hey guys, I just switched from mongoDB to convex.
I created some functions on my nextJS app, and connected it to my current front-end:
- one dev dashboard to insert mocked data to try my app
- one admin dashboard for the clients to insert/read data
But the mutations on the admin dashboard are not being called, but it works perfectly using the dev dashboard, but the way of calling the API is exactly the same.
Please can someone take some time with me to up on a call and try resolve this issue with me ?
14 Replies
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 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!
Could you share any relevant parts of your code that are tied to this issue?
Hey, thanks for for trying to help me.
this is the files:
1) the api file from /convex used on the dev dashboard to create false data
2) the component using it (and it is working)
3) the function inside mutation.ts that I try to call inside the admin dashboard:
export const createClient = mutation({
args: { name: v.string() },
handler: async (ctx, { name }) => {
console.log('Creating client with args:', name)
try {
const clientId = await ctx.db.insert('clients', {
name: name,
})
console.log('Client created with ID:', clientId)
return clientId
} catch (error) {
console.error('Error in createClient mutation:', error)
throw new Error(
Failed to create client: ${error}
)
}
},
})4) the modal helper calling the client mutation (not working)
#2 above confuses me. The way you're using
mutation
doesn't conform with the way it's shown in the docs. The docs show passing an object to mutation
with args
and handler
properties, with args
being an object containing data validators, and handler
being an async function that runs when using the mutation. You say that your version works, but I'm not sure how based on this variance from the docs.
This also makes me wonder if there are other variations from the usage shown in the docs in the places where you're trying to consume this mutation function.Are you following a pattern similar to the example shown here? https://docs.convex.dev/functions/mutation-functions#calling-mutations-from-clients
Mutations | Convex Developer Hub
Mutations insert, update and remove data from the database, check authentication
that is also confusing me. To be honest, the 2) is a file created by an AI that knew my repository to create false data on convex from a mocked_data.ts and the way it work is weird.
So I'm lost too, I don't understand why the code I have that doesn't look like the documentation is working when the code I have that look exactly like the documentation does not work
this is an alternative way to define a mutation btw (it's the old way from before we had argument validation)
the most important files too look are the 3) & 4), as it is the real use case of my app. And as you see I think I did a code pretty close to the documentation
ok so maybe I don't have the right version and it explain why the new way is not working for me ?
my version: "@convex-dev/react-query": "^0.0.0-alpha.5",
my package.json if it helps
it looks like you're defining the mutations correctly. in what way are they not getting called? do they show up in the Convex dashboard Logs page? are there errors in the browser console?
two slight issues in the code, which could be nothing or might be hiding bugs:
- you should await the promise
await createClientMutation({ name: formData.Chateau as string })
- you shouldn't need to be casting like selectedWine.id! as Id<'wines'>,
. the types should flow through the system if they are correctthe front end component calling the mutation create logs but when it should call the convex function it seem to just stop: no log from convex (convex dashboard or website) and no log from my app either
ok I will try that
Ok I just tried and it is not working for any of the mutations. Even with the old code I had. What issue could it be ? Could it be on your side ? Or maybe because I use an external auth provider and didn't configure it well