fides icon indicating copy to clipboard operation
fides copied to clipboard

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

Open allisonking opened this issue 2 years ago • 0 comments

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 avatar Oct 11 '22 17:10 allisonking