c# - GraphQL : Not Getting EF Related objects afte

对于背景,我正在按照此处的教程进行操作:https://www.youtube.com/watch?v=HuN94qNwQmM .

由于代码太长,我将其放在 git https://github.com/dikeshkumar135/CommandERGQL 中

现在,问题来了,当我向这个机构提出请求时

    query{
     platform{
       id,
       name,
       commands{
         howTo
       }
     }
    }

我正在获取平台的数据,命令值为 null 并出现以下错误:

{
  "message": "There was no argument with the name `platform` found on the field `commands`.",
  "locations": [
    {
      "line": 5,
      "column": 5
    }
  ],
  "path": [
    "platform",
    1,
    "commands"
  ],
  "extensions": {
    "fieldName": "commands",
    "argumentName": "platform"
  }

如果我删除类型,它工作正常,但如果我添加类型,那么在获取相关对象时就会出现问题。

最佳答案

在 HotChocolate v12 中,ResolverWith 方法中包含的 DependecyInjection 将所有参数假定为 Argument。除了以下

There are also specific arguments that will be automatically populated by Hot Chocolate when the resolver is executed. These include Dependency injection services, DataLoaders, state, or even context like a parent value.

Documentation Source

这是您正在使用的教程升级的一些示例

public IQueryable<Command> GetCommands(
    [Parent] Platform platform,
    [ScopedService] AppDbContext context)
{
    return context.Commands.Where(p => p.PlatformId == platform.Id);
}

关于c# - GraphQL : Not Getting EF Related objects after implementing Types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69602080/

相关文章:

kotlin - 获取列表 kotlin 范围之间的项目

javascript - 使用 reduce,从一个对象数组中,在对象的数组属性中创建一组元素

c++ - 我的结果并不是真正随机的;我怎样才能解决这个问题?

azure-devops - Azure Devops yml 管道 if else 条件变量

haskell - 为什么我的 ByteString 在我的 x86_64 架构上是 BigEndi

arrays - 为什么我在执行 strcat() 时得到错误的源字符串输出?

android - 您上传的文件不是格式正确的 zip 存档

c# - 从 Swagger (Swashbuckle) 隐藏参数

python - 为什么在为 python 安装 psutil 包时会出现错误?

haskell - 如何使组合数据构造函数成为类的实例?