feat: introduce transformRelated() for smart and isolated relationship transformations#10278
feat: introduce transformRelated() for smart and isolated relationship transformations#10278datamweb wants to merge 5 commits into
transformRelated() for smart and isolated relationship transformations#10278Conversation
Shouldn't the behavior of |
@michalsn The issue actually isn't inside If the URL is // The leak happens right here, before transformMany() is even called!
$transformer = new CommentTransformer(); Because we don’t pass a custom |
|
On a related note, one of the main reasons I was so keen on introducing Right now, if we want to support advanced API queries like:
Handling this with the old architecture would have been a nightmare because the global state leakage made child transformers unpredictable. However, now that |
michalsn
left a comment
There was a problem hiding this comment.
Okay, I looked into the actual code. While this new method can be really handy as API sugar, which we can promote as the default method to use, this doesn't really fix the underlying problem.
I will try to prepare something as a bugfix targeting the develop branch.
Description
This PR introduces a new method
transformRelated(), to theBaseTransformerclass to solve the Global State Leakage issue when transforming nested/related resources, and to simplify the developer experience.Previously, the documentation instructed developers to manually instantiate transformers for included resources:
This approach caused a significant issue: if a request contained query parameters like
?include=or?fields=, those global states could unintentionally leak into the child transformers, leading to incorrect field filtering, infinite loops, orApiExceptions.Checklist: