patrickP
tRPC3y ago
39 replies
patrick

Is it possible to narrow an output schema if the query optionally doesn't return all fields?

I have a router procedure that has an input schema that has an optional filter that changes the shape of the data to only include those fields (like sql select), but those records will fail the output schema which contains all of the fields as required. is there a way to construct a .output() specification that narrows the type, possibly using z.partial() so that these partial "rows" will pass output validation?
Was this page helpful?