#give me a custom query, which calls an endpoint which is 'v2/comments/' and has a name listComments.
2 messages · Page 1 of 1 (latest)
Here’s a minimal Convex query named listComments that reads from a v2/comments table. Since you said “this is a custom query, defined in Convex only and not a 3rd party call,” this does not use fetch and just queries the Convex database.
// convex/comments.ts
import { query } from "./_generated/server";
import { v } from "convex/values";
export const listComments = query({
// Add args if you want pagination or filtering later
args: {
// example: postId: v.id("posts"),
},
handler: async (ctx, args) => {
// Query the "v2/comments" table
// Adjust filters / ordering as needed
return await ctx.db
.query("v2/comments")
// .withIndex("by_postId", q => q.eq("postId", args.postId)) // example
.order("desc")
.collect();
},
});