Skip to content
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

Combine our RTK API's into one API instance for better cache re-fetching and tags #1386

Closed
allisonking opened this issue Oct 11, 2022 · 5 comments · Fixed by #3059
Closed
Assignees
Labels
Tech Debt UI Work related to UI

Comments

@allisonking
Copy link
Contributor

allisonking commented Oct 11, 2022

Is your feature request related to a specific problem?

RTK recommends only having one call to createApi and then injecting more endpoints off of the one instance.

Typically, you should only have one API slice per base URL that your application needs to communicate with. For example, if your site fetches data from both /api/posts and /api/users, you would have a single API slice with /api/ as the base URL, and separate endpoint definitions for posts and users. This allows you to effectively take advantage of automated re-fetching by defining tag relationships across endpoints.

For maintainability purposes, you may wish to split up endpoint definitions across multiple files, while still maintaining a single API slice which includes all of these endpoints. See code splitting for how you can use the injectEndpoints property to inject API endpoints from other files into a single API slice definition.

Describe the solution you'd like

We should refactor our endpoints to this pattern so that it's easier to control cache invalidation across different endpoints. We have ~14 slice files that all create their own API instance.

Describe alternatives you've considered, if any

A description of any alternative solutions or features you've considered.

Additional context

I came across this because I wanted the /plus/scan endpoint to invalidate the existing datamap cache, but they would need to be the same API instance first.

@allisonking allisonking added enhancement UI Work related to UI labels Oct 11, 2022
@allisonking
Copy link
Contributor Author

The unified-fides-resources branch already does some of this, so let's work on this after that feature branch is merged in.

@rsilvery
Copy link
Contributor

@allisonking is this still needed?

@allisonking
Copy link
Contributor Author

@allisonking is this still needed?

Yes! I've been picking at it as other features are built but there are still a good number of instances where we aren't doing this yet. This shouldn't be difficult to do though

@allisonking
Copy link
Contributor Author

Leaving a note to myself that I ran into this reduxjs/redux-toolkit#2484, should be able to work around it though

@Roger-Ethyca
Copy link
Contributor

moving to done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tech Debt UI Work related to UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants