无法让它运行。我得到以下错误消息,我已经使它尽可能简单,但什么是必需的服务,我错过了。
我正在使用图类型第一方法。https://graphql-dotnet.github.io/docs/getting-started/introduction
GraphQL.Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider提供者找不到的
System.InvalidOperationException: GraphQL.Types.SchemaTypes.<>c__DisplayClass7_0.<.ctor>b__2(Type t中的 33中的serviceType) )在//src/GraphQL/Types/Collections/SchemaTypes.cs:line 141中的GraphQL.Types.SchemaTypes.AddTypeIfNotRegistered(Type类型,( //src/GraphQL/Types/Collections/SchemaTypes.cs:line 539 at GraphQL.Types.SchemaTypes.HandleField(IComplexGraphType parentType,FieldType字段,TypeCollectionContext上下文,布尔applyNameConverter)在//src/GraphQL/Types/Collections/SchemaTypes.cs:line 429 at GraphQL.Types.SchemaTypes.AddType(IGraphType type,TypeCollectionContext context)中,//src/GraphQL/Types/Collections/SchemaTypes.cs:line 333 at GraphQL.Types.SchemaTypes..ctor(ISchema模式,//src/GraphQL/ Types/Schema.cs://src/GraphQL/ GraphQL.Utilities.SchemaPrinter.PrintFilteredSchema(Func
2 directiveFilter, Func2 /Schema.cs中//src/GraphQL/Types/Schema.cs中GraphQL.Types.Schema.Initialize()的第328行()第328行://src/GraphQL/ IServiceProvider /Schema.cs中的GraphQL.Types.Schema.Initialize()第79行//src/GraphQL/实用程序/SchemaPrinter.cs: Autumn.Api.Controllers.AutumnController.Schema()的第63行,C:\ws\Autumn-APICore\Autumn.Api\Controllers\AutumnController.cs:line 37中的Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper映射程序,ObjectMethodExecutor执行器、对象控制器、Object[]参数)
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());
}
}
}发布于 2021-08-11 13:50:45
错误是AutumnQuery是不需要的,并且在构造函数IServiceProvider中有
https://stackoverflow.com/questions/68733119
复制相似问题