Annotation Interface Source


@Retention(RUNTIME) @Target(PARAMETER) @Documented public @interface Source
Extends a GraphQL type by adding an externally defined field, effectively enabling a graph to be assembled.

The GraphQL type which is extended is the GraphQL type corresponding to the Java type of the annotated method parameter.

The added field type can be a scalar or another GraphQL type, it's inferred from the method return type.

At runtime, injects the concerned source object (which type is the extended GraphQL type), thus allowing to use fields from it to resolve the added field.

Optionally, specifies the name and description of the added field in the extended GraphQL type. By default, the name of the added field is the name of the method.

For example, a user might annotate a method's parameter as such:
 public class CharacterService {
      @Inject TwitterService twitterService;

     @Query(value = "tweets")
     @Description = "Get the last tweets for a character")
     public List<Tweet> tweets(
                          @Source("tweetsForMe") @Description("Get the last tweets for the character") Character character,
                          @Argument("last") @Description = "Number of last tweets to fetch") int last) {
          return twitterService.search(character.getName(), last);
     }
 }
 

Schema generation of this would result in a stanza such as:

 type Character {
    # Other fields ...

    # Get the last tweets for the character
    # last: Number of last tweets to fetch
    tweetsForMe(last: Int): [Tweet]
 }
 
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
     
  • Element Details

    • name

      String name
      Returns:
      the name of the added type in the extended GraphQL type.
      Default:
      ""