【问题标题】:HotChocolate: How to bind directive to field from resolver with [ExtendObjectType]HotChocolate:如何使用 [ExtendObjectType] 将指令绑定到解析器中的字段
【发布时间】:2021-06-03 17:54:17
【问题描述】:

想象一下这个 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?

【问题讨论】:

    标签: .net hotchocolate


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-24
      • 2017-01-07
      • 1970-01-01
      • 2015-09-27
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      相关资源
      最近更新 更多