Is there a way to append a transform to a zod schema? #1229
Replies: 2 comments 1 reply
-
In Kubb you can use 'parser' to use Zod in react-query: https://www.kubb.dev/plugins/swagger-tanstack-query/#parser. Could that help out or is more needed? |
Beta Was this translation helpful? Give feedback.
-
@stijnvanhulle Bumping this again. Is there anything I can do to map data from a DTO to an object I want stored in the query cache? This is happening because the API I'm using has responses that look like this:
I don't want to store the entire object, I just want to map data and store that in the query cache. But without a selector I have to write wrappers for every hook that kubb generates |
Beta Was this translation helpful? Give feedback.
-
Currently we receive DTO's that we need to reshape and we would like to define zod transforms on the end of the schema to map between objects, and have the resulting type used in react query instead. Is there any way to do that, or would we need to use templates if we wanted it part of the automated generation?
Effectively i want something like this pseudo code to be output
getPetByIdQueryResponseSchema.transform(petDTO=> pet).parse() where pet is stored in the react query cache instead of petDTO
Beta Was this translation helpful? Give feedback.
All reactions