Factories / Usage (Symfony) #387
Unanswered
christian-lorenz
asked this question in
Q&A
Replies: 1 comment 5 replies
-
@christian-lorenz can you please re-state the actual issue here? It sounds like you're frustrated about something, but I'm not entirely sure what. Is it the verbosity? What's your goals here? What would you like to see or improve in your design? The factories do not have to be in the Entity dir. We do not have ours there and wouldn't put them there either. We have a separate namespace for all our GraphQL logic, outside the Entity namespace. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm struggling a little bit with the best way on how to mutate data.
Let's say, I've got an entity "Article" with like 20+ fields. And maybe some OneToMany stuff in there like "ArticleElement" or whatever.
The "normal" way to handle an edit would be:
getArticleById(int $id) :Article
)updateArticle(int $id, string $title, DateTimeImmutable $publishDate, bool $isFeatured , ...) :Article
)Which looks very exhausting to me.
So I gave Factories a shot, mutating with an ArticleInput instead.
But it looks like I'm just moving that Problem to another (weird - as the factory has to be in the entity folder?) place, as now the factoryMethod needs to look like:
getArticle(int $id, string $title, ...)
and I've got to set the data and do some business logic (throwing exceptions if article not found, uploading an image ...) already there before the Article-entity gets injected into the gqlController-mutation-action.I'm quite sure, this can't be the right way.
This maybe just works on small brainless models (like the Location class in the examples).
So what would be the best way for this "real world" example? Would these Proxy classes help in that case?
Beta Was this translation helpful? Give feedback.
All reactions