patrick
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
40 replies
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
.query(async ({ input: options }) => {
const result = await queryRows(client, options);
if (options?.select) {
const picker = options.select.reduce<Record<string, true>>((a, f) => {
a[f] = true;
return a;
}, {});
const resultSchema = schema.pick(picker).array();
resultSchema.parse(result);
} else {
schema.array().parse(result);
}
return result;
}),
40 replies