How to get the schema definitions
I need help with getting the full paths to all functions from a single
api
variable.
I'm building a tool; with this tool, I want to pass my convex generated api
variable. Within the tool, I would like to access all the properties it has. I went deep in the codebase and realized this is inferred from typescript. The actual api
is a Proxy object.
How do I get all the routes from a single api
variable on the client side? On the server side, I can parse the api.d.ts
file and do what I want. On the client, I do not have direct access to the file, is there a workaround?12 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!
Digging deeper
https://stack.convex.dev/code-spelunking-uncovering-convex-s-api-generation-secrets#typescript-secrets
It may not be possible the way I imagined
Code Spelunking: Uncovering Convex's API Generation Secrets
As the newest member of the Convex team I am keen to find out how the magic works. Join me as I go spelunking through the codebase and uncover how the...
Hm yeah doing something like
Object.entries(api)
just returns an empty array. I guess maybe this Proxy approach is used to make it impossible to enumerate all the api endpoints at runtime for security purposes?
I guess you could build some kind of script or helper function in your convex folder to produce this array of endpoints based on the folder structure. AI would probably be really good at this, or maybe you can even find the function that Convex uses to do this to create the api
object?Yeah. I thought about that; since convex already does this, trying to redo this may not be ideal but it is a way out.
I wish there was something to hook into this build within Convex and grab the schema. I'll go with the naive approach for now, read the api.d.ts file on the server and create a manifest JSON file
@ballingt Would you mind adding your 2 cents to this?
My approach is as follows:
- Add a program that generates a manifest in the generated folder. The manifest is a pure array mapping function names and to their full reference.
The program listen to changes to the api.d.ts file, scans the file and generate the function mappings in the manifest file anytime there is a change to the api.d.ts. It scans all the imported files in
The problm I have with this is that I feel like I’ll be rebuilding what is already being built but badly within convex; all the file watching etc. Is there a simpler and more efficient way out? Probably a way to hook into convex
api.d.ts
, searches for functions that are exported that contains query, internalQuery, mutstion etc only; it ignores pure functions. (Using regex)
- This would also require you run the convex dev sxript concurrently with the program’s manifest generator. convex dev & mytool-generate-manifestThe problm I have with this is that I feel like I’ll be rebuilding what is already being built but badly within convex; all the file watching etc. Is there a simpler and more efficient way out? Probably a way to hook into convex
doCodegen
outputs in realtime?Have you seen OpenAPI spec generation? https://docs.convex.dev/client/open-api
or probably more useful, https://stack.convex.dev/multiple-repos
https://docs.convex.dev/production/multiple-repos
These all don't use TypeScript, they get a list of functions from the last push to dev/prod
Thank you @Tom
The OpenAPI spec generation wouldn't work for my use-case, it's local and don't need to call HTTP endpoint; but the convex-helpers solution might be what I need. That is close to what I need
@Tom The api is a proxy, in my case I need a pure object and not the types; but with this, I do not have to manually traverse to get the function names, I can scan this file and generate mappings from it.

My goal is to have a list like this on the client side like we have on the convex dashboard

Doesn't this openapi generation give you the names and the types?
it's local and don't need to call HTTP endpointyour solution is local, and can't call an http endpoint? Just in case you haven't seen it,
npx convex function-spec
does this but isn't local; but you could run a backend locally and use the commandHi @ballingt
Thank you. The function-spec is exactly what I needed. Appreciate your help so far. I'm good to go. 🙏
Hi @ballingt , one more thing. I want to run
npx convex function-spec
after Convex functions ready
, is there a way to hook / listen to this event from another library?
The Goal: I want to regenerate the function spec only when there is a change to the convex directory (assuming something in the spec would also change)
Hi @ballingt In case you missed this. I still need help if you come across this
One approach is to listen to the stderr or stdout data events from the terminal. I'm going with that approach for now