rtk-incubator / rtk-query

Data fetching and caching addon for Redux Toolkit
https://redux-toolkit.js.org/rtk-query/overview
MIT License
626 stars 31 forks source link

Redux Toolkit: responseHandler should always be serializable #155

Closed gfortaine closed 3 years ago

gfortaine commented 3 years ago

Addresses points brought up in https://github.com/rtk-incubator/rtk-query/issues/154

We have a use case where we need to consume the headers of the response. It looks like that we could handle this case through responseHandler by returning the raw Response : (response) => response. However, it seems that Redux Toolkit complains when responseHandler is a function (because it is not serializable). Thus, it appears that a suitable approach would be to simply add 'raw' as a potential responseHandler type, then to handle the raw Response with transformResponse (see corresponding tests).

codesandbox-ci[bot] commented 3 years ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bc75d642539cf38e9d9c360f9d84827911080a1f:

Sandbox Source
React Configuration
React Typescript Configuration
rtk-query-demo Configuration
svelte-app-rtk-simplequery-demo Configuration
phryneas commented 3 years ago

I'll take a look tomorrow. It seems reasonable, but I want to check if we don't have other options that lead the the same pitfall. You have seen that you can use the codesandbox build above meanwhile?

gfortaine commented 3 years ago

OK, looking forward to your review tomorrow 👌By the way, many thanks for the codesandbox tip, I hadn’t seen it 👍

phryneas commented 3 years ago

Unfortunately, there's a bunch of other options with the same problem. I've opened #156 to try and find a more broad solution. Can you take a look please?

gfortaine commented 3 years ago

Solved by #156