Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Splitting API Definitions with RTK Query

I have three API definitions in my current scenario.

  • Groups
  • Group Members
  • Group Invitations

These routes relate to each other, in that accepting a group invitation will invalidate the list of groups a user has. As a result, I have defined them under the same API as they need to invalidate shared tags.

However, this results in quite a bloated file, as each of those definitions have their own endpoints associated with them. Reading the documentation for Code Splitting with RTK Query suggests using injectEndpoints. This looks like it will suit my purposes, but I’ve the documentation has no examples that I can find of how it should be implemented with multiple ‘sub’ endpoints.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have a couple questions;

  1. If I was to utilize injectEndpoints to extend the Groups API with GroupInvitations & GroupMembers seperately, which API should be included in the call to configureScore?
  2. Is there a way to inject both endpoints into Groups at once, resulting in a single combinedApi?

>Solution :

  1. You always only configure your one emptyApi in your store setup. All the other "apis" you get by calling injectEndpoints are just a reference to that same api – but with additional types for autocomplete.

  2. Sure, just add multiple endpoints to the endpoints value of the injectEndpoints call.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading