Wrapped base query mutating API responses - is it possible to get generated hooks to have correct typing (without manual endpoint return type annotation) ? #4619
Unanswered
robert-westenberger
asked this question in
Q&A
Replies: 1 comment
-
This is related to #4616 , but I thought this question is different enough to warrant another discussion. Let me know if this should be closed and I'll post this in #4616. Also I struggled to come up with a good title for this post |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am generating an api slice using @rtk-query/codegen-openapi . Here is one of the generated slices ( okay, its actually handwritten for the sake of this post )
Every endpoint has the same APIResponse schema:
I want to "unwrap" every single API response before it's even cached in redux, so that when I use the generated hooks, i get back, not { success: true, result: }.
I do that by wrapping the base query.
The issue I am having is that I have to manually annotate the API slice definitions to let typescript know that I am "unwrapping" the payload for every query, like this:
Is there a way to do this in a more.. i don't know, "automatic" way? I realize there might not be since I have a very niche use case here. I want to avoid overriding the result type for every endpoint.
Beta Was this translation helpful? Give feedback.
All reactions