The @Source annotation is a very convenient way of mixing fields from different domains into a single query without polluting the source entity with unrelated fields:
class SuperHero { String id, name; }
class Team { String id, name; }
Team team(@Source SuperHero superHero) {
return teamRepository.getTeamFor(superHero);
}
But this doesn't work for input types (e.g. for mutations): they need the fields to be added explicitly, e.g. a team field in the SuperHero. Maybe we could add an @Target annotation as an alternative:
void team(@Target SuperHero superHero, Team newTeam) {
teamRepository.updateTeamFor(superHero, newTeam);
}
- The
SuperHeroInput type would have a team field, even when the SuperHero class doesn't.
- When a client passes a
SuperHeroInput in a request that contains a team field, the core mutation is called ignoring the team field, although this field doesn't exist in the SuperHero class. But the above team method is called just after.
- If the parameter annotated as
@Target is also annotated as @Source, then the method is also mapped into the result object, using the method name as the field name and the return type as the field type.
The
@Sourceannotation is a very convenient way of mixing fields from different domains into a single query without polluting the source entity with unrelated fields:But this doesn't work for input types (e.g. for mutations): they need the fields to be added explicitly, e.g. a
teamfield in theSuperHero. Maybe we could add an@Targetannotation as an alternative:SuperHeroInputtype would have ateamfield, even when theSuperHeroclass doesn't.SuperHeroInputin a request that contains ateamfield, the core mutation is called ignoring theteamfield, although this field doesn't exist in theSuperHeroclass. But the aboveteammethod is called just after.@Targetis also annotated as@Source, then the method is also mapped into the result object, using the method name as the field name and the return type as the field type.