How to actually override fetchBaseQuery #2097
Replies: 3 comments 9 replies
-
The example in the docs does not call an api endpoint - you would need to share some code what you are doing here. |
Beta Was this translation helpful? Give feedback.
-
Adding code examples. api/backend/index.tsx
api/backend/users/index.ts
It gives me this error when importing on the users endpoints file
|
Beta Was this translation helpful? Give feedback.
-
Ok, so I found out what was happening. What happens is that when using the method extraReducers while adding any "matchers" that use a given api endpoint, if overriding the fetchBaseQuery, it is important to not dispatch any action imported from that slice. Specifically, I was dispatching a signOut action when the token renewal request failed. This signOut action was dependent on the slice, while the slice was dependant on conclusion of the API's endpoints Injections. Working on a solution that dispatches an action not imported from anywhere else..... |
Beta Was this translation helpful? Give feedback.
-
Hello, I want to extend fetchBaseQuery so that I have an automatic refresh of token when given an 401 (like seen on this guide: https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#automatic-re-authorization-by-extending-fetchbasequery)
The problem is that I get a circular dependency error from webpack ("error - ReferenceError: Cannot access 'backendApi' before initialization"). The code is pretty straightforward, the only thing that stands out is that I am using injectEndpoints for splitting my code.
If anyone has any idea on how to actually implement the custom baseQuery please help
Beta Was this translation helpful? Give feedback.
All reactions