【发布时间】:2020-08-17 02:44:00
【问题描述】:
我正在使用 Graphql .Net 库来构建 GraphQl API。 以下是我们目前拥有的域示例,其中,该区域有一个采样点标识符列表:
public class AreaRoot {
public String Id { get; set; }
public List<String > SamplingPointIds { get; set; }
}
public class SamplingPointRoot {
public String Id { get; set; }
public String Description { get; set; }
}
类型定义如下:
public class AreaType : ObjectGraphType<AreaRoot>
{
public AreaType()
{
Name = "Area";
Field(x => x.Id, type: typeof(IdGraphType));
Field(x => x.SamplingPointIds, type: typeof(ListGraphType<StringGraphType>));
}
}
public class SamplingPointType : ObjectGraphType<SamplingPointRoot>
{
public SamplingPointType()
{
Name = "SamplingPoint";
Field(x => x.Id, type: typeof(IdGraphType));
Field(x => x.description, type: typeof(StringGraphType));
}
}
有什么方法可以在不更改域类的情况下从采样点检索所有内容?在会议GraphQL vs Traditional Rest API 中有一个示例,在 25:41 分钟内,但是这个示例是用 java 编写的,我们无法使用 graphQl .net 制作相同的示例。
下一个示例说明了我们想要进行的查询类型:
query GetAreas(){
areas(){
Id
samplingPoints{
Id
description
}
}
}
所以问题是:有没有办法像上面的视频中那样,当我们传递采样点并解决它,检索该区域的采样点(在某些查询中)?
【问题讨论】: