@rtk-query/codegen-openapi and transformResponse #3506
-
I am generating from a large openapi.yaml file using codegen-openapi. It works well. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
you would need to use 1.9.4+currently changing the ResultType of an endpoint is fairly complicated: import type { DefinitionsFromApi, TagTypesFromApi, OverrideResultType } from "@reduxjs/toolkit/dist/query/endpointDefinitions"
import { api } from "./autogenerated"
type Definitions = DefinitionsFromApi<typeof api>
type TagTypes = TagTypesFromApi<typeof api>
type UpdatedGetPostsDef = OverrideResultType<Definitions["getPosts"], EntityState<Post>>
type UpdatedDefinitions = Omit<Definitions, { getPosts: UpdatedGetPostsDef }>
const enhanced = api.enhanceEndpoints<TagTypes, UpdatedDefinitions>({
endpoints: {
getPosts: {
transformResponse: (posts) => postAdapter.setAll(postAdapter.getInitialState(), posts)
}
}
}) There's also an open issue for this inference not working correctly, which there is an open PR for. 2.xIn 2.0, we're investigating replacing enhanceEndpoints completely, with separate const enhanced = api.enhanceEndpoint('getPost', {
transformResponse: (posts) => postAdapter.setAll(postAdapter.getInitialState(), posts)
}) The PR for this is #3485. |
Beta Was this translation helpful? Give feedback.
-
thank you for the help. is there an eta on the 2.0 version? in a few months? |
Beta Was this translation helpful? Give feedback.
-
fairr enough. |
Beta Was this translation helpful? Give feedback.
you would need to use
enhanceEndpoints
.1.9.4+
currently changing the ResultType of an endpoint is fairly complicated: