.net - HotChocolate:如何使用 [ExtendObjectType] 将指令绑定到解析器中的字段
问题描述
想象一下这个 ObjectType 带有来自 FooResolver 的字段“bars”,并用 BazDirective 注释
public class FooResolver {
public IEnumerable<Bar> GetBars(string name) {/*omitted*/}
}
public class FooType: ObjectType<Foo>
{
protected override void Configure(IObjectTypeDescriptor<Foo> descriptor) {
descriptor.Field<FooResolver>(_ => _.GetBars(default)).Directive<BazDirective>();
}
}
如果我们改为使用扩展绑定
class FooType: ObjectType<Foo> {}
[ExtendObjectType(Name="Foo")]
class FooResolver {
[/* how to bind BazDirective? */]
public IEnumerable<Bar> GetBars(string name) {/* omitted */}
}
如何绑定 BazDirective?
解决方案
解决方案是使用可用于在字段上添加额外信息的自定义 DescriptorAttributes。
https://github.com/ChilliCream/hotchocolate-docs/blob/master/docs/descriptor-attributes.md
推荐阅读
- python - 为什么我的 python 函数 sum_points 总是返回相同的结果?
- android - 适用于旧 android 版本的芯片组
- java - MySql Workbench 上未显示数据
- c++ - 带有随机数的 C++ 字符串练习
- angular - 如何测试方法的返回值 [Jasmine]
- powershell - 通过 PowerShell 向组授予 SharePoint Online 文件夹权限
- python - 如何使用列表理解并在每次字符串包含单词时放置 1
- c++ - 具有外部定义的默认特殊成员函数
- c - C中代码的错误功能。程序似乎显示垃圾
- winapi - Winapi - 如何为 MS Edge 浏览器实现等效的 LWA_COLORKEY