正在设置 GraphQL.net
Setting up GraphQL.net
无法将此发送到 运行。我收到以下错误消息,我已将其尽可能简单化,但我缺少所需的服务。
我正在使用图形类型优先方法。
https://graphql-dotnet.github.io/docs/getting-started/introduction
System.InvalidOperationException: Required service for type
autumn.TestOGT not found at
GraphQL.Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider
provider, Type serviceType) in
//src/GraphQL/Utilities/ServiceProviderExtensions.cs:line 33 at
GraphQL.Types.SchemaTypes.<>c__DisplayClass7_0.<.ctor>b__2(Type t) in
//src/GraphQL/Types/Collections/SchemaTypes.cs:line 141 at
GraphQL.Types.SchemaTypes.AddTypeIfNotRegistered(Type type,
TypeCollectionContext context) in
//src/GraphQL/Types/Collections/SchemaTypes.cs:line 539 at
GraphQL.Types.SchemaTypes.HandleField(IComplexGraphType parentType,
FieldType field, TypeCollectionContext context, Boolean
applyNameConverter) in
//src/GraphQL/Types/Collections/SchemaTypes.cs:line 429 at
GraphQL.Types.SchemaTypes.AddType(IGraphType type,
TypeCollectionContext context) in
//src/GraphQL/Types/Collections/SchemaTypes.cs:line 333 at
GraphQL.Types.SchemaTypes..ctor(ISchema schema, IServiceProvider
serviceProvider) in
//src/GraphQL/Types/Collections/SchemaTypes.cs:line 154 at
GraphQL.Types.Schema.CreateSchemaTypes() in
//src/GraphQL/Types/Schema.cs:line 328 at
GraphQL.Types.Schema.Initialize() in
//src/GraphQL/Types/Schema.cs:line 102 at
GraphQL.Utilities.SchemaPrinter.PrintFilteredSchema(Func2 directiveFilter, Func
2 typeFilter) in
//src/GraphQL/Utilities/SchemaPrinter.cs:line 79 at
GraphQL.Utilities.SchemaPrinter.Print() in
//src/GraphQL/Utilities/SchemaPrinter.cs:line 63 at
Autumn.Api.Controllers.AutumnController.Schema() in
C:\ws\Autumn-APICore\Autumn.Api\Controllers\AutumnController.cs:line
37 at
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper
mapper, ObjectMethodExecutor executor, Object controller, Object[]
arguments)
using GraphQL.Types;
using System;
namespace autumn
{
public class Test
{
public int Number { get; set; } = 5;
public string String { get; set; } = "Test Class";
public DateTime DateTime { get; set; } = System.DateTime.Now;
}
public class TestOGT : ObjectGraphType<Test>
{
public TestOGT()
{
Field(x => x.Number, nullable: true).Name("Number");
Field(x => x.String, nullable: true).Name("String");
Field(x => x.DateTime, nullable: true).Name("DateTime");
}
}
public class AutumnQuery : ObjectGraphType
{
public AutumnQuery()
{
Field<TestOGT>("Article",
arguments: new QueryArguments(
new QueryArgument<StringGraphType> { Name = "Language", DefaultValue="en-us" },
new QueryArgument<StringGraphType> { Name = "Id" }
),
resolve: context => { return new Test(); });
}
}
public class AutumnSchema : Schema
{
public AutumnSchema(IServiceProvider serviceProvider, AutumnQuery query) : base(serviceProvider)
{
this.Query = query;
}
}
[ApiController]
[Route("[controller]")]
public class AutumnController : ControllerBase
{
private static readonly HttpClient client = new HttpClient();
private readonly AutumnSchema _schema;
public AutumnController(ISchema schema)
{
_schema = (AutumnSchema)schema;
}
[HttpGet]
[Route("/schema")]
public async Task<IActionResult> Schema()
{
return Content(new SchemaPrinter(_schema).Print());
}
}
}
错误是在构造函数 IServiceProvider 中不需要 Autumn Query
无法将此发送到 运行。我收到以下错误消息,我已将其尽可能简单化,但我缺少所需的服务。
我正在使用图形类型优先方法。 https://graphql-dotnet.github.io/docs/getting-started/introduction
System.InvalidOperationException: Required service for type autumn.TestOGT not found at GraphQL.Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) in //src/GraphQL/Utilities/ServiceProviderExtensions.cs:line 33 at GraphQL.Types.SchemaTypes.<>c__DisplayClass7_0.<.ctor>b__2(Type t) in //src/GraphQL/Types/Collections/SchemaTypes.cs:line 141 at GraphQL.Types.SchemaTypes.AddTypeIfNotRegistered(Type type, TypeCollectionContext context) in //src/GraphQL/Types/Collections/SchemaTypes.cs:line 539 at GraphQL.Types.SchemaTypes.HandleField(IComplexGraphType parentType, FieldType field, TypeCollectionContext context, Boolean applyNameConverter) in //src/GraphQL/Types/Collections/SchemaTypes.cs:line 429 at GraphQL.Types.SchemaTypes.AddType(IGraphType type, TypeCollectionContext context) in //src/GraphQL/Types/Collections/SchemaTypes.cs:line 333 at GraphQL.Types.SchemaTypes..ctor(ISchema schema, IServiceProvider serviceProvider) in //src/GraphQL/Types/Collections/SchemaTypes.cs:line 154 at GraphQL.Types.Schema.CreateSchemaTypes() in //src/GraphQL/Types/Schema.cs:line 328 at GraphQL.Types.Schema.Initialize() in //src/GraphQL/Types/Schema.cs:line 102 at GraphQL.Utilities.SchemaPrinter.PrintFilteredSchema(Func
2 directiveFilter, Func
2 typeFilter) in //src/GraphQL/Utilities/SchemaPrinter.cs:line 79 at GraphQL.Utilities.SchemaPrinter.Print() in //src/GraphQL/Utilities/SchemaPrinter.cs:line 63 at Autumn.Api.Controllers.AutumnController.Schema() in C:\ws\Autumn-APICore\Autumn.Api\Controllers\AutumnController.cs:line 37 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
using GraphQL.Types;
using System;
namespace autumn
{
public class Test
{
public int Number { get; set; } = 5;
public string String { get; set; } = "Test Class";
public DateTime DateTime { get; set; } = System.DateTime.Now;
}
public class TestOGT : ObjectGraphType<Test>
{
public TestOGT()
{
Field(x => x.Number, nullable: true).Name("Number");
Field(x => x.String, nullable: true).Name("String");
Field(x => x.DateTime, nullable: true).Name("DateTime");
}
}
public class AutumnQuery : ObjectGraphType
{
public AutumnQuery()
{
Field<TestOGT>("Article",
arguments: new QueryArguments(
new QueryArgument<StringGraphType> { Name = "Language", DefaultValue="en-us" },
new QueryArgument<StringGraphType> { Name = "Id" }
),
resolve: context => { return new Test(); });
}
}
public class AutumnSchema : Schema
{
public AutumnSchema(IServiceProvider serviceProvider, AutumnQuery query) : base(serviceProvider)
{
this.Query = query;
}
}
[ApiController]
[Route("[controller]")]
public class AutumnController : ControllerBase
{
private static readonly HttpClient client = new HttpClient();
private readonly AutumnSchema _schema;
public AutumnController(ISchema schema)
{
_schema = (AutumnSchema)schema;
}
[HttpGet]
[Route("/schema")]
public async Task<IActionResult> Schema()
{
return Content(new SchemaPrinter(_schema).Print());
}
}
}
错误是在构造函数 IServiceProvider 中不需要 Autumn Query