-
-
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
Return type of transformResponse on enhanceEndpoints can not differ from original definition in createApi #1441
Comments
I just ran into this myself. A bit annoying. However, I think I understand why this limitation might exist. Disclaimer: My team uses React hooks, so I don't know much about how But what I do know, is that The same hooks that get returned from e.g. if a React component imports a Therefore, changing the return type of The only way that a change of return type would be realistically possible, would be if But that sounds really complicated and potentially confusing to use. |
It is theoretically possible, but depending on what file you import from you will get things of different types - and So we kinda stayed away from it for now. But I understand the use and I will take another look into it, given the time. |
(Thanks for rtkq, I'm transitioning some code to it now and it's amazing.) I don't know if one of the things that's holding this up is lack of ideas for how to make it ergonomic, but in case that is the issue I have an idea that might work as a jumping off point for brainstorming. In the OpenAPI context -- which is where I think of this coming up the most -- would it be possible to handle this by treating the enhancing api as an intermediate phase specified in config, changing the way that code generation ends up? What I'm imagining is that where right now the I can imagine that if a user specifies a trio of new As a walkthrough of the simple case of only one input file: Where right now you specify: const config = {
schemaFile: "...",
apiFile: "empty.ts",
apiImport: "empty",
outputFile: "api.ts",
} You could add const config = {
schemaFile: "...",
apiFile: "empty.ts",
apiImport: "empty",
enhanceInputFile: "middle.ts", // <-- new
enhanceInputExport: "middle", // <-- new
enhanceFile: "enhance.ts", // <-- new
enhanceImport: "enhance", // <-- new
outputFile: "api.ts"
} The openapi-codegen program then generates the After that, the Then, the openapi codegen reads this new file, does magic with types -- or just requires that all types be defined explicitly in the middle file -- and outputs basically a duplicate of the Does that seem... possible? |
That's no problem for me personally, as I'm only going to import from the Anyway, you still change the api instance type in terms of tags, so I don't see why not in terms of return types |
If you want to open a PR to it, I'd be open for it. I just don't have the time to work on that at the moment. |
+1 I am using codegen for GraphQL queries and would like transform the result. |
Currently, the return type of
transformResponse
onenhanceEndpoints
has to match the original return type fromcreateApi
.This diminishes the value and ability of
enhanceEndpoints
:Often, it is preferred to have client code use different shapes than the ones exposed by an API and
transformResponse
is the mechanism to do so.However, once RTK codegen is used,
transformResponse
should be defined onenhanceEndpoints
and not on the (generated)createApi
.Example
Using the
enhancedEndpoints
example from the docs, this usage oftransformResponse
currently fails to compile:The text was updated successfully, but these errors were encountered: