#ignore folder name in api

7 messages · Page 1 of 1 (latest)

remote talon
#

I want a base folder called features and then feature folders inside like users, organizations, etc. but I dont want to call it as api.features.users and want to call it like api.users. But I don't want a ton of folders at the root of my convex folder

random saffronBOT
#

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

#

There isn’t currently a supported way to “hide” a folder name from the generated api path (for example, to have files under convex/features/users.ts show up as api.users.* instead of api.features.users.*).

Convex’s codegen uses the folder and file path inside the Convex functions directory directly to determine the API path — whatever comes after api. mirrors that path, and there’s no configuration for collapsing or ignoring intermediate folders like features or (group) folders. [Feature managementDifferent root folders]

Related ideas have been discussed (e.g. ignoring bracketed folders like (internal) or (loyalty)), but staff have confirmed these are not features today, just potential future improvements. [Feature request: better file managementBracket folders discussion]

So right now your options, within what’s documented, are:

  • Put users.ts, organizations.ts, etc. directly under convex/ if you need api.users.* and api.organizations.*.
  • Or accept api.features.users.* if you keep them under convex/features/.

There’s no convex.json or .convexignore setting that changes this mapping today. [convex.json config]

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

#

@remote talon Kapa.ai is still learning and improving, please let me know how I did by reacting below.

remote talon
random saffronBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Yes.

In that thread, support suggested exactly this pattern on the frontend:

// frontend
const myApi = api.functions;

This works because api.functions is just a sub-tree of the full Convex API object. [Different root folders]

Applied to your case:

  • Suppose your Convex files are under convex/features/organizations.ts, so you normally call api.features.organizations.someFn.

  • On the frontend you can alias:

    import { api } from "../convex/_generated/api";
    
    const myApi = api.features;
    
  • Now you can call myApi.organizations.someFn instead of api.features.organizations.someFn.

So you can’t change the generated path, but you can create a shorter alias like myApi = api.features and then use myApi.organizations in your app.

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