想象一下这个ObjectType带有字段"条";来自FooResolver,带有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