【问题标题】:There was no argument with the name `...` found on the field `...`在“...”字段中找不到名称为“...”的参数
【发布时间】:2021-11-25 19:20:32
【问题描述】:

我使用的是 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-understanding-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>()

问题可能出在哪里?

【问题讨论】:

  • 我在this tutorial也遇到了这个问题:/我试过调试,好像没有使用解析器

标签: asp.net-core graphql hotchocolate


【解决方案1】:

真是愚蠢的解决方案,我花了 4 个小时才找到。

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

相关文档:

【讨论】:

  • 这正是我所需要的。有一些 YouTube 教程是在 V11 上编写的,这个简单的解决方案解决了这个问题。谢谢!
  • 是的,我不知道为什么这会被深深地埋在文档中,哈哈
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-02
相关资源
最近更新 更多