You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow @Factory annotation directly on input type classes #285
I could have sworn there was a discussion on this topic some time back. I looked around and couldn't find the ticket or a pull request, but maybe I'm overlooking it. If anyone can link that other ticket that'd be great.
But basically, this ticket is to discuss the fact that factory methods are often times nothing but boilerplate. In fact, I've only had to modify input fields a handful of times to date. These methods mostly consist of taking in params and passing them directly to properties of the input type. In fact, in our case, they already have the same names as well. I'd assume this is similar for most.
What this proposes is making the @Factory annotation optionally defined on the input type class, itself. I don't even see any need for args to handle anything here, just a direct mapping, when the annotation is defined on the input type class.
As for how the properties are populated, it's probably best that, like the factory method today, all of the properties assignments are passed to the input type class' constructor. This would also allow for some light field modification if someone deemed that necessary. For example taking a date string and instantiating a Date object to assign to the class' property.
Assuming the above with the constructor, the question then becomes, do you put the @Factory annotation on the constructor or the class?
The other thing that I'll add to this, because I know it'd be an issue for us, is validation. We do also add a simple validation call within our input type factories. Assuming this gets implement, I think there should also be a way to register an InputTypeValidatorInterface with the schema, that would then be called when an input type is constructed, passing that newly constructed input type object.
After thinking on this a little further, I've progressed my recommendation for this issue. Instead of the aforementioned solution, which requires a more opinionated approach, I'd like to see a way to register an InputType Factory Service that can handle all InputType requests. By taking this route, effectively overriding the current logic which is out looking for @Factory annotations and corresponding method names, you'd register a service that can bypass all of this, allowing for you to instantiate and build your input types however you best see fit.
We've been able to boil down, virtually all of our factory classes and methods, to the following example. There are only a handful of InputTypes that need a defined factory method on our API now. With a registered factory "service", we'd be able to delete almost every factory class.
Activity
oojacoboo commentedon Jul 16, 2020
After thinking on this a little further, I've progressed my recommendation for this issue. Instead of the aforementioned solution, which requires a more opinionated approach, I'd like to see a way to register an InputType Factory Service that can handle all InputType requests. By taking this route, effectively overriding the current logic which is out looking for
@Factoryannotations and corresponding method names, you'd register a service that can bypass all of this, allowing for you to instantiate and build your input types however you best see fit.@moufmouf thoughts?
oojacoboo commentedon Sep 25, 2020
We've been able to boil down, virtually all of our factory classes and methods, to the following example. There are only a handful of
InputTypesthat need a defined factory method on our API now. With a registered factory "service", we'd be able to delete almost every factory class.We're able to handle domain level mapping for common type/class mappings, validation and error response through the
makemethod.oojacoboo commentedon Mar 29, 2021
Issue resolved with #269