Annotation Type GraphQLFactory


@Documented
@Retention(RUNTIME)
@Target({METHOD,CONSTRUCTOR})
public @interface GraphQLFactory
Annotation used to mark a constructor or function as a factory. Used together with GraphQLObject to define automatic conversions from other types.

This allows a GraphQL type to be automatically created from another type, like this:

 class DataObject {
   public String id;
 }

 @GraphQLObject
 class DataObjectQueryType {
   private final DataObject object;

   @GraphQLFactory
   public DataObjectQueryType(@GraphQLSource DataObject source) {
     this.object = object;
   }

   @GraphQLField
   public String id() {
     return object.id;
   }
 }
 

Factories can also be static methods, which works for GraphQLObject and GraphQLEnum:

 class DataObjectQueryType {
   private final String id;

   public DataObjectQueryType(String id) {
     this.id = id;
   }

   @GraphQLField
   public String id() {
     return object.id;
   }

   @GraphQLFactory
   public static DataObjectQueryType create(@GraphQLSource DataObject object) {
     return new DataObjectQueryType(object.id);
   }
 }