GraphQL:实现类型后未获取 EF 相关对象
GraphQL : Not Getting EF Related objects after implementing Types
对于背景,我正在按照此处的教程进行操作: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"
}
如果我删除类型,它工作正常,但如果我添加类型,那么在获取相关对象时就会出现问题。
我将热巧克力包从 12.0.1 降级到 11.0.8 并且有效。这是对我在 youtube 上的评论的建议。
如果您没有更新数据的目标,您可以省略使用 EF 并使用,例如,NReco.GraphQL 通过 [=13] 设置 graphql 模式(包括模式对象之间的关系) =]-样式定义。设置 db-connection 非常简单,并且在底层是 ORM。
在 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.
这是您正在使用的教程的一些升级示例
public IQueryable<Command> GetCommands(
[Parent] Platform platform,
[ScopedService] AppDbContext context)
{
return context.Commands.Where(p => p.PlatformId == platform.Id);
}
这是我的类型class
public class MajorType : ObjectType<Major>
{
protected override void Configure(IObjectTypeDescriptor<Major> descriptor)
{
descriptor.Description("Offer Degree from the university");
descriptor.Field(p => p.MinCreditHours).Description("Minimum credit hours for the degree");
descriptor.Field(p => p.SetUser).Ignore();
descriptor.Field(p => p.SetDate).Ignore();
descriptor.Field(p => p.IsDeleted).Ignore();
descriptor.Field(p=>p.Courses)
.UseDbContext<CatalogueDBContext>()
.ResolveWith<Resolvers>(p=>p.GetCourse(default!,default!))
.Description("Avialable coures for the specific major");
}
private class Resolvers
{
public IQueryable<Courses> GetCourse([Parent] Major major, [ScopedService] CatalogueDBContext context)
{
return context.Courses.Where(c=>c.MajorId == major.Id);
}
}
}
对于背景,我正在按照此处的教程进行操作: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"
}
如果我删除类型,它工作正常,但如果我添加类型,那么在获取相关对象时就会出现问题。
我将热巧克力包从 12.0.1 降级到 11.0.8 并且有效。这是对我在 youtube 上的评论的建议。
如果您没有更新数据的目标,您可以省略使用 EF 并使用,例如,NReco.GraphQL 通过 [=13] 设置 graphql 模式(包括模式对象之间的关系) =]-样式定义。设置 db-connection 非常简单,并且在底层是 ORM。
在 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.
这是您正在使用的教程的一些升级示例
public IQueryable<Command> GetCommands(
[Parent] Platform platform,
[ScopedService] AppDbContext context)
{
return context.Commands.Where(p => p.PlatformId == platform.Id);
}
这是我的类型class
public class MajorType : ObjectType<Major>
{
protected override void Configure(IObjectTypeDescriptor<Major> descriptor)
{
descriptor.Description("Offer Degree from the university");
descriptor.Field(p => p.MinCreditHours).Description("Minimum credit hours for the degree");
descriptor.Field(p => p.SetUser).Ignore();
descriptor.Field(p => p.SetDate).Ignore();
descriptor.Field(p => p.IsDeleted).Ignore();
descriptor.Field(p=>p.Courses)
.UseDbContext<CatalogueDBContext>()
.ResolveWith<Resolvers>(p=>p.GetCourse(default!,default!))
.Description("Avialable coures for the specific major");
}
private class Resolvers
{
public IQueryable<Courses> GetCourse([Parent] Major major, [ScopedService] CatalogueDBContext context)
{
return context.Courses.Where(c=>c.MajorId == major.Id);
}
}
}