Night
Night3y ago

Defining Convex functions

Could someone explain why the Convex functions have to return a function rather than returns the value directly? Asking for a friend.
3 Replies
alexcole
alexcole3y ago
Hey! I'm not sure I totally follow. Pulling an example from our quickstart (https://docs.convex.dev/quickstart), defining a Convex function looks like:
import { query } from "./_generated/server";

export default query(async ({ db }) => {
return await db.query("messages").collect();
});
import { query } from "./_generated/server";

export default query(async ({ db }) => {
return await db.query("messages").collect();
});
Here, query is signifying that we're writing a query function. Inside of it, we're just writing an async JavaScript function that takes in the database (db) and returns the results. So the thing we are returning is just the array of results (not a function). Does that make sense?
ian
ian3y ago
Are you asking about the ConvexHttpClient?
Night
NightOP3y ago
Hi Alex sorry for the late response. Yes, I think my brain just completely forgot JavaScript arrow syntax for some reason. It's just a function. 🤦‍♂️ No I meant regular Convex mutations and queries.

Did you find this page helpful?