-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transformResponse in enhanceEndpoints returning Promise type when trying to transform the type of the response #3443
Comments
@dmitrigrabov did you find any solution ? Is there a way that I can help ? |
@Mozzarella123 Thanks for the update ! Is this the correct behaviour ? If so, how can I override this to obtain only the ResultType in my components ? |
Hi there, thanks for the report! Apologies for the slow response. The issue appears to be that the utility type used to extract the result from the provided type didn't account for Promises, as the actual execution unwraps that promise. I've opened #3500 that should fix this - if someone could try the build that's created from that PR, that'd be greatly appreciated. In terms of overriding result types, we're investigating (over at #3485) the possibility of replacing const enhanced = api
.addTagTypes('tag1', 'tag2')
.enhanceEndpoint('query1', { providesTags: ['tag1'] })
.enhanceEndpoint('mutation2', (definition) => {
definition.invalidatesTags = ['tag2'];
}) This is of course a big breaking change, so it would be part of RTK 2.0, clearly communicated, and a codemod would most likely be provided to ease the transition. |
Hey, thanks for the update I've tried on my side and it sounds good ! |
Hey @EskiMojo14 thanks for the fix ! I've checked it out and it seems to fix the Promise issue on my side as well ! |
great 😄 both of the other co-maintainers are at conferences this week so I'm unsure when we can get the fix reviewed, merged and published - will try to get it prioritised when possible 🙂 |
Hey @EskiMojo14, Do you have any idea when it can be checked and released ? |
it's been merged into master, but i'm not sure when the next release will be |
@EskiMojo14 Any chance of getting a new release out including this fix? It would be really useful for my team 😄 |
I'll look at trying to get out another release sometime today. |
Hey ! Same as @annaet, would it be possible to get a new release this week ? |
Hi @markerikson. Any updates on getting a new release out? |
Hi @markerikson and @EskiMojo14, I hope you guys are doing well. Sorry to keep pushing this issue, but do you have any updates on when you plan to release this fix ? I am currently working with a specific commit bundle in my package.json, which I think may have expired and is no longer accessible as a yarn package. Any info would be greatly appreciated so that we can plan our releases accordingly. Thanks ! |
I'm on vacation for at least another week, and won't have time to think about doing any releases until after I'm back. |
Alright thanks for the update ! Enjoy your vacation 🍸 🍺 🏖️ |
@cini9 If you are using yarn or pnpm you can use the |
the npm equivalent would be using something like patch-package |
Isn't it already released in v1.9.6? |
Ye, my bad, was on 1.9.5, a simpel upgrade solved my issue :) |
Thanks @cini9 you really helped me solve this problem.
|
Hey @Innders, I'm glad this discussion was able to help you solve this issue 😄. It is indeed useful to be able to modify the response type to fit our applications. I've tried to answer your questions above as best I could, but feel free to ask if you have any other questions.
I'd also love to get the community feedback if anybody has found a better way to do all of this ! |
Cool! I like your file structure... I might have to
Let's say you enhance a simple query and then transform it so it just returns the number of edges in the response. The first bit works great. ![]() Now let's say you want to update the cache of that same query using The draft for the cache uses the original query type not the transformed type (number). ![]() Maybe this is a bug in
Makes sense as you would only ever need to have new arguments if you were using
This might be a good place: #3692 |
|
Following the update to V1.9.4, with the ability to override TS type of the original data in transformResponse of enhanceEndpoints, the response type I am receiving in my components are being additionally transformed to add a Promise<> type of my desired response type.
I am using codegen to generate types from my backend, but need to transform that response to extract lower-level data from the raw graphql query response.
This gives me the typing in the components in the screen shot below, with my correct type (id: string, firstName: string, etc) followed by the Promise<...> type.
When I try to use the data returned from these queries, I'm getting a 'property id does not exist on type Promise< .... >'
Is there any way to tell RTK to not add the Promise type when we are overriding the response type in transformResponse ?
Thanks in advance for your help !
The text was updated successfully, but these errors were encountered: