public IReadOnlyCollection <HumanModel> GetAll() { var humans = _humansRepository.GetAll(); var result = _mapper.Map <IReadOnlyCollection <HumanModel> >(humans); return(result); }
private object GetHumans(ResolveFieldContext <object> arg) { var humans = _humanRepository.GetAll().Result; return(humans); }
public RootQuery( IDroidRepository droidRepository, IHumanRepository humanRepository) { Connection <HumanGType>() .Name("humans") .Argument <StringGraphType>("filter", "Filter humans") .Unidirectional() .PageSize(10) .ResolveAsync(async context => { var filter = context.GetArgument <string>("filter"); Console.WriteLine($"filter => {filter}"); if (filter == null) { var result = await humanRepository.GetAll(context.CancellationToken); return(result.ToConnection(context)); } else { var result = await humanRepository.GetAll(context.CancellationToken); return(await result.AsQueryable().Where(filter).ToConnection(context)); } }); Connection <DroidGType>() .Name("droids") .Argument <StringGraphType>("filter", "Filter droids") .Unidirectional() .PageSize(10) .ResolveAsync(async context => { var filter = context.GetArgument <string>("filter"); Console.WriteLine($"filter => {filter}"); if (filter == null) { var result = await droidRepository.GetAllAsync(context.CancellationToken); return(await result.ToConnection(context)); } else { var result = await droidRepository.GetAllAsync(context.CancellationToken); return(await result.AsQueryable().Where(filter).ToConnection(context)); } }); //this.Name = "Query"; //this.Description = "The query type, represents all of the entry points into our object graph."; //this.FieldAsync<DroidGType, Droid>( // "droid", // arguments: new QueryArguments( // new QueryArgument<IdGraphType> // { // Name = "id", // Description = "The unique identifier of the droid.", // }), // resolve: context => // droidRepository.GetAsync( // context.GetArgument("id", defaultValue: new Guid("1ae34c3b-c1a0-4b7b-9375-c5a221d49e68")), // context.CancellationToken)); //this.FieldAsync<HumanGType, Human>( // "human", // arguments: new QueryArguments( // new QueryArgument<IdGraphType>() // { // Name = "id", // Description = "The unique identifier of the human.", // }), // resolve: context => humanRepository.GetAsync( // context.GetArgument("id", defaultValue: new Guid("94fbd693-2027-4804-bf40-ed427fe76fda")), // context.CancellationToken)); //this.FieldAsync<ListGraphType<HumanGType>, List<Human>>( // "humans", // resolve: context => humanRepository.GetHumans(context.CancellationToken)); }
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 IList <Human> GetHumans() { return(_humanRepository.GetAll().Result); }