Ejemplo n.º 1
0
        public StarSystemsQuery(IStarSystemRepository starSystemRepository)
        {
            Field <ListGraphType <StarSystemType>, IEnumerable <StarSystem> >()
            .Name("starSystems")
            .Argument <IntGraphType>("WithinLightYearsOfEarth")
            .Argument <BooleanGraphType>("predictPlanetRadii", "return an estimated planetary radius if an observed radius does not exist")
            .ResolveAsync(async context => {
                var starSystems = await starSystemRepository.GetStarSystemsAsync();
                var maxDistance = context.GetArgument <int?>("WithinLightYearsOfEarth");
                if (maxDistance != null)
                {
                    starSystems = starSystems.Where(ss => ss.Distance < maxDistance);
                }
                return(starSystems);
            });

            Field <StarSystemType, StarSystem>()
            .Name("starSystem")
            .Argument <NonNullGraphType <IdGraphType> >("id", "id of the star system")
            .Argument <BooleanGraphType>("predictPlanetRadii", "return an estimated planetary radius if an observed radius does not exist")
            .ResolveAsync(async context => {
                var id = context.GetArgument <int>("id");
                return(await starSystemRepository.GetStarSystemAsync(id) !);
            });
        }
Ejemplo n.º 2
0
 public async Task <ActionResult <IEnumerable <StarSystem> > > GetStarSystems()
 {
     return((await _starSystemRepository.GetStarSystemsAsync()).ToList());
 }