Doogibo
Doogibo
CCConvex Community
Created by Doogibo on 12/13/2024 in #support-community
VERCEL_URL - dynamic Convex env
Hey there! I need to figure out the best way to handle VERCEL_URL. We are constructing clerk invitations in our Convex functions and need to generate a redirect url for the invitations. We want this to work for our preview deploys and prod. Prod is easy technically as it's a static domain and we could just explicitly set VERCEL_URL in the dashboard, but this doesn't work for previews. So what is the best/easiest option for setting this in Convex during Vercel deployments? Thank you!
26 replies
CCConvex Community
Created by Doogibo on 11/29/2024 in #support-community
Conditionally Building Queries
Having trouble figuring out how to do the following without TypeScript complaining. I want to start a query like this:
let query = ctx.db.query("requests");
let query = ctx.db.query("requests");
And conditionally add to it. Then later for an indexed query:
query = query.withIndex('by_this_and_that', q => {
const baseQuery = q.eq('this', user._id);
return status ? baseQuery.eq('that', status) : baseQuery;
})
query = query.withIndex('by_this_and_that', q => {
const baseQuery = q.eq('this', user._id);
return status ? baseQuery.eq('that', status) : baseQuery;
})
Then later, an optional in memory filtering.
query = query.filter(q => {
if (status) {
return q.neq(q.field('status'), 'DRAFT');
}
return q;
})
query = query.filter(q => {
if (status) {
return q.neq(q.field('status'), 'DRAFT');
}
return q;
})
Something like that anyway. But I run into: is missing the following properties from type 'QueryInitializer<{ document: { _id: Id<"requests">; _creationTime: .... etc.
10 replies
CCConvex Community
Created by Doogibo on 10/16/2024 in #support-community
Optional One-To-Many Issue - Ents
Hello! First I want to say I am loving using Convex, so thank you for creating such a fantastic product with a wonderful developer experience. I have read through the issues relating to this and I just want to get final confirmation that what I'm trying to do is not currently possible, and that I am correct about the recommended approach if I am using Ents.
import { defineEnt, defineEntSchema, getEntDefinitions } from "convex-ents";
import { zodToConvex } from "convex-helpers/server/zod";
import { z } from "zod";

const schema = defineEntSchema({
requests: defineEnt(
zodToConvex(
z.object({
name: z.string(),
})
).fields
)
.edge("approvedBy", {
to: "users",
field: "approvedById",
optional: true
})
.edge("createdBy", {
to: "users",
field: "createdById",
})
.edge("requester", {
to: "users",
field: "requesterId",
}),
users: defineEnt(zodToConvex(z.object({ name: z.string() })).fields)
.edges("createdRequests", {
to: "requests",
ref: "createdById",
})
.edges("approvedRequests", {
to: "requests",
ref: "approvedById",
})
.edges("myRequests", {
to: "requests",
ref: "requesterId",
}),
});

export default schema;

export const entDefinitions = getEntDefinitions(schema);
import { defineEnt, defineEntSchema, getEntDefinitions } from "convex-ents";
import { zodToConvex } from "convex-helpers/server/zod";
import { z } from "zod";

const schema = defineEntSchema({
requests: defineEnt(
zodToConvex(
z.object({
name: z.string(),
})
).fields
)
.edge("approvedBy", {
to: "users",
field: "approvedById",
optional: true
})
.edge("createdBy", {
to: "users",
field: "createdById",
})
.edge("requester", {
to: "users",
field: "requesterId",
}),
users: defineEnt(zodToConvex(z.object({ name: z.string() })).fields)
.edges("createdRequests", {
to: "requests",
ref: "createdById",
})
.edges("approvedRequests", {
to: "requests",
ref: "approvedById",
})
.edges("myRequests", {
to: "requests",
ref: "requesterId",
}),
});

export default schema;

export const entDefinitions = getEntDefinitions(schema);
A request needs to have a "requester" and a "createdBy"; however, the approvedBy should be null until a future state when it is approved. I feel like this is a fairly common scenario. The error is Edge "approvedBy" in table "requests" has too many potential inverse; but what the problem really is, is that I cannot add optional. It sounds like the recommendation is to turn it into a many-to-many relationship, which enabled 0-many, even though in this case it doesn't really make sense. Maybe back to the drawing board on the model to find another creative way around this. Thoughts?
3 replies