void
void•3y ago

Using the same Convex deployment for 2 different projects

howdy friends! been a while 🙂 question - is there any recommendations for using the same convex deployments for 2 different projects? i.e. a nextjs UI and a nodejs daemon
5 Replies
ballingt
ballingt•3y ago
hey there! would you keep these in the same repo, just different directories+package.json+tsconfigs?
void
voidOP•3y ago
i think so oh right the convex directory has its own tsconfig doesnt it?
ballingt
ballingt•3y ago
yeah i'm thinking about this, I haven't played with it before it's doable, but our codegen isn't set up for it yet. let's see, I think I'd do codegen in whichever package has the convex/ directory in it, then maybe import the API from ../project/convex/_generated/api and use that to type everything and with a bit of TypeScript gymnastics that could get you there I think there might be trouble if you try to import e.g. useQuery from ../project/convex/_generated/api, but also it might just work. My worry is that it will use the copy of React in the other project. If you just import the types you should be safe from any of these shenanigans
void
voidOP•3y ago
yeah i run into trouble right when i import useQuery haha
ballingt
ballingt•3y ago
if you look at the convex/_generated/react.d.ts file you'll see the code you should put in your other project that is just importing API something like
// convex client api in another project
import type {API} from '../../otherproject/convex/_generated/api';
import type { UseQueryForAPI } from "convex/react";
import { useQueryGeneric } from "convex/react";

export const useQuery = useQueryGeneric as UseQueryForAPI<API>;
// convex client api in another project
import type {API} from '../../otherproject/convex/_generated/api';
import type { UseQueryForAPI } from "convex/react";
import { useQueryGeneric } from "convex/react";

export const useQuery = useQueryGeneric as UseQueryForAPI<API>;

Did you find this page helpful?