oscklmO
Convex Community2y ago
9 replies
oscklm

Working with return validator and a query that enriches data

Hello,

In our project, we use relational tables and in a query like the one below, where we wanna enrich video with its related data. We wanna use this new return validation, but find it a bit hard to get the returned object to actually match the validator we define.

I'd love to ask for some advice on how to best approach this, as we are looking to do it quite a lot with other pieces of data in our app.

Return validator:
export const videoEnrichedValidator = v.object({
  _id: v.id('video'),
  _creationTime: v.number(),
  ...videoValidator.fields,
  enrichments: v.object({
    activity: v.union(v.null(), activityValidator),
    category: v.union(v.null(), categoryValidator),
    thumbnails: v.union(
      v.null(),
      v.object({
        small: v.union(v.string(), v.null()),
        medium: v.union(v.string(), v.null()),
        large: v.union(v.string(), v.null()),
      })
    ),
    muxAsset: muxAssetValidator,
  }),
});
Was this page helpful?