-
-
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
Automatic normalization addon to rtk-query #4073
Comments
Finally have a chance to look at this topic and think about it a bit. I don't think we expose the Can you clarify what you mean by "disable normalization per specific queries"? It sounds like this addon works globally for all RTKQ endpoints and there's no way to isolate it? I don't understand what you're asking for in regards to structural sharing. Can you clarify that question as well? |
If this is a problem, it is not a deal breaker, I was just forced to type rtk actions myself, and I will need to maintain them to make any updates myself as well. Should we do it? If we want to allow people to listen to those actions in middlewares, I think we should.
Please see how it is done for react-query - https://github.com/klis87/normy/tree/master/packages/normy-react-query#disabling-of-normalization-per-query-and-mutation-arrow_up Generally you can:
About use case, you might have a very query with big data, and you know that this data will never be updated, then there is no point normalizing it, so you can disable it. Or, you have a mutation which you know should not update any data, but it receives a big payload, you might want to disable normalization for it to optimize performance, if needed.
In normy core, I have this logic - https://github.com/klis87/normy/blob/master/packages/normy/src/create-normalizer.ts#L65 , which stops doing any update, if it is called with a It works with react-query, for example when this method is called here for instance - https://github.com/klis87/normy/blob/master/packages/normy-react-query/src/create-query-normalizer.ts#L64, it just works, I already have data with the same reference as previous query, if data has the same structure. However, it does not work with rtk-query here - https://github.com/klis87/normy/blob/master/packages/normy-rtk-query/src/index.ts#L143 . Even if you refetch a query which gives you the same response, data is not referentially the same, so structural sharing does not work here. I suspect that rtk query applies structural sharing data transformation on a different level, and I cannot use it. This is extreme optimization, as for example on refocus refetch, you can end up refetching dozens queries, which usually will not change data. With this feature, no normalization will be done for unchanged data, |
Hi, as discussed in #3248 , I integrated rtk-query with normy, a library, which allows automatic normalization and data updates for fetching libraries. There is already react-query and swr integration, now also rtk-query is supported. You can find it here - https://github.com/klis87/normy/tree/master/packages/normy-rtk-query#normyrtk-query
This is to solve problem mentioned here - https://redux-toolkit.js.org/rtk-query/comparison#no-normalized-or-deduplicated-cache and gives you apollo graphql like experience - relevant queries are automatically updated based on mutations results with no additional code.
I raised this issue not only as information, but also to mention several potential improvements, which could require some rtk-query changes
normalizeQuery
andnormalizeMutation
options, but it is global, collocation style inside specific queries and mutations would be much better, like implemented in react-query addon - https://github.com/klis87/normy/tree/master/packages/normy-react-query#disabling-of-normalization-per-query-and-mutation-arrow_updata
is different. it would be cool to have this information in actions, so that middleware could give up normalization for a refetch which did not update data, which is a waste as it will end up with normalization store exactly the same as it was. This would be very nice optimization, especially that rtk-query has features like refetch on refocus, which potentially could cause multiple refetches at the same time.The text was updated successfully, but these errors were encountered: