CabalDAO
CabalDAO6mo ago

Hi how can I run a mutation from my own

Hi how can I run a mutation from my own api route? i.e. not one defined by convex http is there a server side equivelent of useMutation?
3 Replies
Tom Redman
Tom Redman6mo ago
Hey! Are you using Node? If so, you can use the Node SDK: https://docs.convex.dev/client/javascript/node
Node.js | Convex Developer Hub
Convex supports point-in-time queries (see
Tom Redman
Tom Redman6mo ago
import { ConvexHttpClient, ConvexClient } from "convex/browser";
import { api } from "./convex/_generated/api.js";

// HTTP client
const httpClient = new ConvexHttpClient(CONVEX_URL_GOES_HERE);
httpClient.query(api.messages.list).then(console.log);
import { ConvexHttpClient, ConvexClient } from "convex/browser";
import { api } from "./convex/_generated/api.js";

// HTTP client
const httpClient = new ConvexHttpClient(CONVEX_URL_GOES_HERE);
httpClient.query(api.messages.list).then(console.log);
Let me know if you're using another framework for your backend. There's always a way :cat_cool:
CabalDAO
CabalDAOOP6mo ago
Thank you - so there's no way to call it without it going over http? That's fine i just want to make sure i understood correctly. I.e. if I have a an api route or action in nextjs, it would be making a query over http instead of being able to import the function within the code? also do I have to worry about closing the http client after the call? Should i just make one instance of it and import it throughout? Or i can create it on the fly within each call?

Did you find this page helpful?