#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)

gentle vigilBOT
#

Hi @gusty ravine. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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();
  },
});

You can then call this from a client using api.comments.listComments (or whatever path matches the file placement) with a Convex client such as ConvexHttpClient.query or React hooks / TanStack Query. [list query; TanStack queries]

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: