Open krakenfuss opened 1 month ago
We have injectEndpoints
for that, please don't invent your own code splitting patterns.
Thank you for your response!
I came across injectEndpoints
but had the impression that it is more of a workaround than a suitable mechanism for code splitting larger APIs, as it requires continuously updating and extending existing APIs. However, I understand that you might have chosen this approach (and the larger endpoint definition in one file) to maintain type inference of the self-referenced API, correct?
Anyways, thank you for this great tool. I really appreciate your work on it.
Please feel free to close this issue.
the only issue I have so far with injectedEnpoint is that you don't have the TagTypes across your injectedApi's addTagTypes. A temporal workaround is providing external constants types and import to injectedApi.
If you have tagTypes
that you share between apis, you can still define those in the initial createApi
call.
If they are unique to one api, you can keep it inside of that.
If they are shared between e.g. two apis, you could still choose to stack one on top of the other.
We are building an RTK-powered Redux store and encountered an issue with accessing
api.util.updateQueryData
generated bycreateApi
inside an endpoint during API initialization. The manual suggests using the following approach:The example above shows a self-reference of
api
inside the initialisation of itself which is only possible if you write the endpoint definitions inside ofcreateApi
.Our goal instead is to avoid writing lengthy files like proposed and rather use code-splitting for endpoints defined in separate files from the API definition. For example:
Problem
With this setup, there is no safe way to access the generated api inside these files without creating either a circular dependency or encountering an error like
is referenced directly or indirectly in its own initializer
.Example of Circular Dependency
File A
File B
Desired Solution
Ideally, endpoints would receive the
api
via dependency injection. However, we cannot do this without modifyingcreateApi
, as injectingapi
during its initialization is not possible in JavaScript.Current Attempt
Proposed Solution
Would it be possible to inject api into the endpoints setup callback, like so?
Desired API Initialization
This approach would allow for a more modular setup without the risk of circular dependencies. Is this a feasible enhancement to
createApi
?