Skip to content

@Target: resolver methods for input types #349

@t1

Description

@t1

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);
}
  1. The SuperHeroInput type would have a team field, even when the SuperHero class doesn't.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Meeting discussionTo mark issues we want to discuss in the weekly meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions