Closed blongstreth closed 1 year ago
Hi @blongstreth ,
We're helping with project maintenance and reviewing the list of opened PRs and Issues.
This issue was created quite a while ago, we were wondering if you were still interested in the outcome, please let us know if this is the case.
Without an answer by July 1st, 2023, this issue will be closed as "inactive" (and can always be re-opened later on if needed).
Thanks,
Hello:
I am wondering if the ability to include fields automatically from any regular Java object without having to annotate each field with
@GraphQLField
could be something you would consider? The behavior could be similar to Java XML bindings. As a simple first cut, any regular Java object annotated with@GraphQLObject
would automatically have their fields included in the GraphQL object type rather than having to annotate each field with@GraphQLField
. For example:Defining Objects
Any regular Java class can be converted to a GraphQL object type when the object is defined with a
@GraphQLObject
annotation:Long-term it would be nice to provide similar functionality to
javax.xml.bind.annotation.XmlAccessType
andjavax.xml.bind.annotation.XmlRootElement
. Anyway, I have provided a proof of concept listed below by hackingGraphQLAnnotations
class such that it can take a customGraphQLObjectInfoRetriever
. At the very least, if someone could update theGraphQLAnnotations
to allow the ability to customize whether a Java object field is to be included or not would be greatly appreciated for I just don't know how future proof the hack will be.Finally, I wanted to mention that having the ability to import POJOs from libraries which don't allow for annotations would be another feature to consider. See: Support Mixins #242. This is obviously is a more complicated feature but the mechanism could be achieved if we had the ability to provide a custom
GraphQLObjectInfoRetriever
.Regards,
Bradley
Custom annotation used to mark a Java object as a GraphQL object for which all declared fields will be used:
Hack to include object fields:
Ugly, ugly hack which mocks (demonstrates) the
GraphQLAnnotations
default constructor: