Skip to content

[RTK Query] api.util.upsertQueryData not work correctly when has transformResponse #4940

Open
@hieuvuvan

Description

@hieuvuvan

for example

// http GET /admin/post.json
// response json: {"post": {"id": 123, "title": "the post"}}


type Post = {
  id: number;
  title: string;
}

type PostResponse = {
  post: Post
}

export const api = createApi({
  reducerPath: "api",
  baseQuery: fetchBaseQuery(),
  endpoints: (builder) => ({
    getPost: builder.query<Post, void>({
      query: () => `/admin/post.json`,
      transformResponse: (response: PostResponse) => response.post,
      providesTags: ["post"],
    })
  })
})

// Some where in the app

const updatedPost = {
  id: 123,
  title: "My Post"
}

dispatch(api.util.upsertQueryData("getPost", updatedPost)); // this not work, undefined body dispatch

I see it is breaking change from version 2.6.0, i also comment on the commit

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions