【发布时间】:2022-08-18 23:24:33
【问题描述】:
我有一个数据模型ItemData,如下所示:
class ItemData
{
public string StartTime { get; set; }
public string EndTime { get; set; }
// other fields here
}
我想像这样将这两个公开为单个字段Duration。不暴露StartTime 和EndTime
{
\"duration\": {
\"start\": \"12:34\",
\"end\": \"23:45\"
},
// other fields here
}
并输入 ItemType 和 DurationType
ItemType 定义了一个字段 \"duration\" 像这样
descriptor.Ignore(x=> x.EndTime);
descriptor.Ignore(x=> x.StartTime);
descriptor.Field(\"duration\")
.ResolveWith<TheResolver>(resolver => resolver.GetDuration(default!))
.Type<DurationType>();
// other configurations here
端点标有 UseProjection 并使用 EFCore 数据上下文。
当TheResolver.GetDuration() 被调用时,它没有从数据库中获取StartTime 和EndTime 的值。我认为这是因为UseProjection 告诉它不要这样做。
当查询请求 duration 字段时,是否有任何方法可以将 Hot Chocolate 配置为在忽略的字段 StartTime 和 EndTime 上使用投影?
如果指定为忽略的字段,则指定 descriptor.Field(x => x.StartTime).IsProjected(true) 不起作用。
更新:刚刚在他们的 github 上发现了一个问题,看起来他们正在处理它 (Issue #4192 - It\'s not possible to project an ignored property)
标签: c# .net graphql hotchocolate