private object GetHuman(ResolveFieldContext <object> context) { var id = context.GetArgument <int>("id"); var human = _humanRepository.Get(id, include: "HomePlanet").Result; return(human); }
public StarWarsQuery(ITrilogyHeroes trilogyHeroes, IDroidRepository droidRepository, IHumanRepository humanRepository, IMapper mapper) { Name = "Query"; Field <CharacterInterface>( "hero", arguments: new QueryArguments( new QueryArgument <EpisodeEnum> { Name = "episode", Description = "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode." } ), resolve: context => { var episode = context.GetArgument <Episodes?>("episode"); var character = trilogyHeroes.GetHero((int?)episode).Result; var hero = mapper.Map <Character>(character); return(hero); } ); Field <HumanType>( "human", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the human" } ), resolve: context => { var id = context.GetArgument <int>("id"); var human = humanRepository.Get(id, include: "HomePlanet").Result; var mapped = mapper.Map <Human>(human); return(mapped); } ); Field <ListGraphType <HumanType> >( "humans", resolve: context => { var humans = humanRepository.GetAll(include: "HomePlanet").Result; var mapped = mapper.Map <List <Human> >(humans); return(mapped); } ); Field <DroidType>( "droid", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the droid" } ), resolve: context => { var id = context.GetArgument <int>("id"); var droid = droidRepository.Get(id).Result; var mapped = mapper.Map <Droid>(droid); return(mapped); } ); }
public Human GetHuman(int id) { return(_humanRepository.Get(id, include: "HomePlanet").Result);; }