Asp.net-Core

在“…”欄位中找不到名稱為“…”的參數

  • October 6, 2021

我正在使用 HotChocolate 12.0.1。我有以下類型定義:

   public class MyType : ObjectType<My>
   {
       protected override void Configure(IObjectTypeDescriptor<My> descriptor)
       {
           descriptor.Field(p => p.Name)
               .ResolveWith<TestResolver>(r => r.Get(default))
               .Type<IdType>();
           descriptor.Field(p => p.Logo)
               .Type<StringType>();
       }

       private class TestResolver
       {
           public string Get(My my)
           {
               return my.Logo;
           }
       }
   }

我希望在 TestResolver Get(My my) 中註入我的對象,因為它填充了 Logo 值,正如我在範例中看到的那樣: https ://github.com/ChilliCream/graphql-workshop/blob/master/docs/3 -了解-dataLoader.md

但由於某種原因,我從 HotChocolate 參數查找中得到:

   There was no argument with the name `my` found on the field `name`.

我的查詢:

   query {
     my(someId: 123) {
       name
       logo
     }
   }

啟動:

           services.AddGraphQLServer()
               .AddQueryType<QueryType>()
               .AddType<MyType>()

問題可能出在哪裡?

真的很愚蠢的解決方案,我花了 4 個小時才找到。

private class TestResolver
{
   public string Get([Parent] My my)
   {
       return my.Logo;
   }
}

相關文件:

引用自:https://stackoverflow.com/questions/69451691