convex-backend icon indicating copy to clipboard operation
convex-backend copied to clipboard

Convex query/mutation export check

Open R5dan opened this issue 5 months ago • 5 comments

It would be nice that (as well as checking typescript), the cli also checks that every instance of query and mutation is exported in the convex backend. This would help to identify bugs quicker as you won't be relying on a query that you thought "existed"

R5dan avatar Jun 26 '25 10:06 R5dan

Sounds like a great idea. I suspect there are some typescript linters that could help you here (dead code linters like no-unused-vars). If you get something working, let us know. It could end up being a good recommendation for tsconfig.

nipunn1313 avatar Jun 26 '25 18:06 nipunn1313

Note there is a nascent convex ESLint plugin! See https://github.com/get-convex/convex-backend/tree/main/npm-packages/%40convex-dev/eslint-plugin, if you have a rule that works for you would love to include it. That sounds like a good one.

thomasballinger avatar Jun 29 '25 05:06 thomasballinger

I did not know that there was an ESLint plugin, that sounds really useful. I was mostly thinking of adding it to the validation in npx convex dev/deploy. If you would prefer it to just be a ESLint rule instead though I would understand.

R5dan avatar Jun 29 '25 17:06 R5dan

it'd be a bit involved to add to dev/deploy: today dev and deploy bundle up each file matching convex/**/*.ts and send them to the server to be run, where we walk over the module's exports and add them to the dashboard. The bundling process may remove these functions if they aren't used elsewhere! So we'd need to run them first somehow? Or statically analyze the code? Which is what eslin is a nice tool for. It's not invalid code to not to export a mutation, it's just probably not what you want, like other lint rules.

thomasballinger avatar Jun 29 '25 21:06 thomasballinger

I understand, I was thinking of something like the ts checker, where the it runs the ts checker locally and blocks its upload unless you set it to not check. Ultimately up to you though.

R5dan avatar Jul 02 '25 21:07 R5dan