allen
allen
CCConvex Community
Created by allen on 7/20/2024 in #support-community
ctx.db.get() Always returning a Doc<'users'> typed doc
I have multiple queries for multiple documents structured like so:
export default query({
args: {
inviteId: v.id('invites'),
},
handler: async(ctx, args) {
return ctx.db.get(args.inviteId);
}
});
export default query({
args: {
inviteId: v.id('invites'),
},
handler: async(ctx, args) {
return ctx.db.get(args.inviteId);
}
});
The typed return of the ctx.db.get is a Doc<'users'> instead of a Doc<'invites'> (or the respective doc type to the provided arg type). If i inspect the type of the ID on the arg its showing as any. This problem emerged today after upgrade convex to latest and adding Convex Auth. This only seems to impact code where the ID is provided on query/mutation args.
11 replies
CCConvex Community
Created by allen on 7/19/2024 in #support-community
API types are "excessively deep" when Convex Auth is installed.
No description
10 replies
CCConvex Community
Created by allen on 2/13/2024 in #support-community
SendGrid Example?
I am trying the most basic SendGrid implementation in an action (which works fine in regular NodeJs env), but getting the following error, even though I'm not using SendGrids template substitutions. Uncaught TypeError: Cannot read properties of undefined (reading 'substitutionWrappers') The code is as follows:
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
await sgMail.send({
to,
subject,
from,
text,
});
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
await sgMail.send({
to,
subject,
from,
text,
});
Anyone have success integrating SendGrid in Convex?
8 replies
CCConvex Community
Created by allen on 2/12/2024 in #support-community
WebStorm File Cache Conflict on File Save
No description
30 replies
CCConvex Community
Created by allen on 1/4/2024 in #support-community
undefined < Number === true?
I have an optional expiresAt field in my schema that holds an expiration date for a record. If its undefined, it should never expire. I have an index on this field as I have a cron job running every minute to see what should be expired. That query looks like so:
db
.query('requests')
.withIndex('by_expiration', (q) =>
q.eq('isExpired', false).lte('expiresAt', Date.now()),
)
db
.query('requests')
.withIndex('by_expiration', (q) =>
q.eq('isExpired', false).lte('expiresAt', Date.now()),
)
However, this returns records that have an undefined value for the expiresAt field, requiring me to filter these in memory with:
.filter((q) => q.neq(q.field('expiresAt'), undefined))
.filter((q) => q.neq(q.field('expiresAt'), undefined))
Being this runs so frequently, its eating through my db bandwidth, retrieving these unwanted rows. Before I get cute with my schema to hack around this... 1) Is this the intended behavior of the query engine? It doesnt match javascript's behavior. 2) Is there a way to better structure or query my existing index to remove these results?
17 replies
CCConvex Community
Created by allen on 5/17/2023 in #support-community
Schedule 'signature'?
Has there been thought to dedupping scheduled calls at the runAt/runAfter execution time of multiple invocations with the same name/args signature? Eg: if I have a updateUser mutation that schedules an action of doThing with {userId} as the args to runAfter 60 seconds, could additional schedules of the same signature be dedupped into this same schedule runner so that only one invocation happens per 60 seconds?
6 replies
CCConvex Community
Created by allen on 5/16/2023 in #support-community
Optimistic update from action?
I have an action that invokes a mutation. What is the best way to optimistically update the cache for the queries affected by the action-invoked mutation client side?
6 replies
CCConvex Community
Created by allen on 5/10/2023 in #support-community
Optimistic Update on Paginated Query
Is there an example of an optimistic update on a paginated query? I'm unsure of how the paginationOpts are cache-keyed to make sure I can get the right item from cached.
const current = store.getQuery('messages/queries/messages', {
type: 'inbox',
paginationOpts: {}, //what goes here to make sure I get whatevers current?
});
const current = store.getQuery('messages/queries/messages', {
type: 'inbox',
paginationOpts: {}, //what goes here to make sure I get whatevers current?
});
For context, what I'm trying to accomplish is when a doc is soft deleted, ensure it is optimistically removed from the paginated result set(s) its present in.
13 replies
CCConvex Community
Created by allen on 4/17/2023 in #support-community
Field name $id starts with a '$', which is reserved.
I started getting this error this morning when invoking an action. Not much further information or stack trace and cant find anything code using $id in my app.
5 replies
CCConvex Community
Created by allen on 4/14/2023 in #support-community
Query optional field on schema
I am looking to query an optional field with .eq('fieldName', undefined), however, I am getting the error: [Error: Uncaught Error: undefined is not a valid Convex value. To learn about Convex's supported types, see https://docs.convex.dev/using/types. The provided docs say to use null but that then breaks generated types from optional fields, as the available options are number | undefined. I could refactor this into a union of a number or a null value, but figured I'd ask first as it seems like it should be possible to query an optional field directly.
6 replies
CCConvex Community
Created by allen on 4/6/2023 in #support-community
Crypto dependency
It seems that the convex client has a dependency on the Crypto API (https://developer.mozilla.org/en-US/docs/Web/API/Crypto) which is not available in the React Native runtime. I am encountering this when trying to optimistically insert a document into the local cache. Even if I don't lean on the crypto api directly like the documentation suggests (https://docs.convex.dev/client/react/optimistic-updates#complex-example) and provide a different random string, it still seems the convex client attempts to use this api. Before I go hunting for a polyfill or shim, I was wondering if there is another approach I can take.
20 replies
CCConvex Community
Created by allen on 4/4/2023 in #support-community
Paginated query briefly returning empty array
I'm observing a defective behavior where a newly mounted paginated query briefly returns an empty array before returning a result set. The expected behavior is that it returns undefined until results are ready. This results in my app rendering an empty state view instead of a loading view while this query is in flight. There is some async linked document population that occurs, but I'm unsure why that would impact the query resolution. The basic design of my query is as follows:
export default query(
async ({ db }, opts) => {
const results = await db
.query('messages')
.paginate(opts);

const page = await Promise.all(
results.page.map(async (item) => {
return {
...item,
focus: (await db.get(item.focusId)) as Doc<'focuses'>,
fromUser: (await db.get(item.fromUserId)) as Doc<'users'>,
};
}),
);

return {
isDone: results.isDone,
continueCursor: results.continueCursor,
page,
};
},
);
export default query(
async ({ db }, opts) => {
const results = await db
.query('messages')
.paginate(opts);

const page = await Promise.all(
results.page.map(async (item) => {
return {
...item,
focus: (await db.get(item.focusId)) as Doc<'focuses'>,
fromUser: (await db.get(item.fromUserId)) as Doc<'users'>,
};
}),
);

return {
isDone: results.isDone,
continueCursor: results.continueCursor,
page,
};
},
);
12 replies
CCConvex Community
Created by allen on 3/31/2023 in #support-community
Paginated Query Design
Lets say you have a table of messages, and you have two views in your app: Inbox and Archived. What is the best way to design pagination queries for these two views that optimizes caching and is responsive to messages ingressing and egressing these states? 1) two separate query functions with fixed filters 2) one query with an arg to denote which messages we are currently interested in 3) doesnt matter 4) something else entirely
34 replies
CCConvex Community
Created by allen on 3/30/2023 in #support-community
Auth not working for some users
I have the same codebase running from two devices for two users and seeing two different sets of behavior and unsure how to resolve. My client does the following:
const createUser = useMutation('users/mutations/createUser');
...
await convexClient.setAuth(async () => getToken({ template: 'convex' }));
await createUser(); //
const createUser = useMutation('users/mutations/createUser');
...
await convexClient.setAuth(async () => getToken({ template: 'convex' }));
await createUser(); //
For one user, everything works as expected. For another, my createUser mutation throws because the request isnt authorized (auth.getUserIdentity() returns null). I have verified that a JWT is returned from getToken. I set a timeout prior to calling the mutation of 1000ms to see if there was a race condition, but that produced the same results. I am unsure how to further debug this or inspect why setAuth doesnt appear to be functioning in this case.
17 replies
CCConvex Community
Created by allen on 3/29/2023 in #support-community
Title of function with export name
No description
12 replies