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) !); }); }
public async Task <ActionResult <StarSystem> > GetStarSystemNode(int id) { var starSystem = await _starSystemRepository.GetStarSystemAsync(id); if (starSystem == null) { return(NotFound()); } return(starSystem); }
public StarType(IPlanetRepository planetsRepository, IStarSystemRepository starSystemRepository) { Field(s => s.StarId, nullable: false, type: typeof(IdGraphType)); Field(s => s.StarName, nullable: false).Description("Primary designation of this star"); Field(s => s.SpectralType, nullable: false); Field(s => s.BvColorIndex, type: typeof(FloatGraphType)); Field(s => s.AbsoluteMagnitude, type: typeof(FloatGraphType)); Field(s => s.Mass, type: typeof(FloatGraphType)); Field(s => s.Radius, type: typeof(FloatGraphType)); Field(s => s.Luminosity, type: typeof(FloatGraphType)); Field(s => s.Temperature, type: typeof(FloatGraphType)); Field(s => s.Age, type: typeof(FloatGraphType)); Field(s => s.Metallicity, type: typeof(FloatGraphType)); Field(s => s.DiscoveryYear, nullable: true, type: typeof(IntGraphType)); Field <ListGraphType <PlanetType>, IEnumerable <Planet> >() .Name("planets") .ResolveAsync(context => planetsRepository.GetPlanetsByStarIdAsync(context.Source.StarId)); Field <StarSystemType, StarSystem>() .Name("starSystem") .ResolveAsync(context => starSystemRepository.GetStarSystemAsync(context.Source.StarSystemId) !); }