Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Target: resolver methods for input types #349

Open
t1 opened this issue Nov 26, 2020 · 0 comments
Open

@Target: resolver methods for input types #349

t1 opened this issue Nov 26, 2020 · 0 comments
Labels
Meeting discussion To mark issues we want to discuss in the weekly meeting

Comments

@t1
Copy link
Contributor

t1 commented Nov 26, 2020

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.
@phillip-kruger phillip-kruger added the Meeting discussion To mark issues we want to discuss in the weekly meeting label Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meeting discussion To mark issues we want to discuss in the weekly meeting
Projects
None yet
Development

No branches or pull requests

2 participants