HotChocolate:如何使用 [ExtendObjectType] 将指令绑定到来自解析器的字段

HotChocolate: How to bind directive to field from resolver with [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?

解决方案是使用可用于在字段上添加额外信息的自定义描述符属性。

https://github.com/ChilliCream/hotchocolate-docs/blob/master/docs/descriptor-attributes.md