-
Notifications
You must be signed in to change notification settings - Fork 0
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
[fix] Mapping #37
Merged
Merged
[fix] Mapping #37
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a significant gap between resources coming from Entities and resources (proper) coming from ApiResources.
To quickstart the v4 prototype we worked with entities as API resources, super charging them with
#[API\...]
attributes and other API Platform goodies, however this was not sustainable in the long term, the problem with this approach started surfacing with two of the resources:Accountings are resources that can be owned by a number of other resources. They have a polymorphic relationship with their owner. This is a concept that does not exist in Doctrine-land, and the Accounting entity has several owner properties, one for the type of owner it has, and several others, each one for the actual owner it has. Outputting this in the API is highly inconvenient, hard to document and represent, and we could simply do better.
Gateways are resources that do not exist in Doctrine-land, at all. They do not come from any database that the app connects to, they come from the codebase itself, these resources represent concrete, available code implementations for processing charges and checkouts with an specific payment gateway or mechanism.
We were getting by with custom state providers for the Gateways and Accountings, but the gap snowballed exponentially with the introduction of GatewayCheckout and GatewayCharges, which are entities, for they are records that need to be stored in the database, but they relate Accountings and Gateways, from the ApiResource world, with Entities.
That is when serialization problems start to arise, as API Platform was trying to serialize Accountings as Resources, but then reading objects which specified an Entity Accounting. Along with other problems under the hood, such as context changes and central object uncertainty.
To avoid this the solution is to keep both domains separated, and specifying the conversion steps from entites to resources and the other way around. This allows us to be in control of the data flow and makes API Platform avoid the problems previously mentioned. However this also makes us now responsible for creating and maintaining A LOT of new code as we now need an additional DTO for each Entity (the ApiResource), custom state providers and processors, and mapping classes for the providers and processors to know how to convert from entity to resource.
This PR aims to minimize that amount of code by: