GraphQL:实现类型后未获取 EF 相关对象

Dik*_*mar 2 .net c# .net-core graphql

对于背景,我正在遵循此处的教程:https://www.youtube.com/watch?v =HuN94qNwQmM 。

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

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

    query{
     platform{
       id,
       name,
       commands{
         howTo
       }
     }
    }
Run Code Online (Sandbox Code Playgroud)

我正在获取命令值为 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"
  }
Run Code Online (Sandbox Code Playgroud)

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

小智 7

在 HotChocolate v12 中,方法DependecyInjection中包含的ResolverWith所有参数均假定为Argument. 除以下情况外

当执行解析器时,Hot Chocolate 还会自动填充一些特定的参数。其中包括依赖注入服务、DataLoaders、状态,甚至像父值这样的上下文。

文档来源

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

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