0

无法让它运行。我收到以下错误消息,我已使其尽可能简单,但我缺少所需的服务。

我使用的是图形类型第一方法。 https://graphql-dotnet.github.io/docs/getting-started/introduction

System.InvalidOperationException:在 GraphQL.Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) in / /src/GraphQL/Utilities/ServiceProviderExtensions.cs: GraphQL.Types.SchemaTypes 的第 33 行中找不到类型 fall.TestOGT 所需的服务。 <>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: GraphQL.Types.SchemaTypes.HandleField(IComplexGraphType parentType, FieldType field, TypeCollectionContext context, Boolean applyNameConverter) in / 的第 539 行/src/GraphQL/Types/Collections/SchemaTypes.cs: GraphQL.Types.SchemaTypes.AddType(IGraphType type, TypeCollectionContext context) 的第 429 行//src/GraphQL/Types/Collections/SchemaTypes.cs: GraphQL 的第 333 行。 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: GraphQL.Types.Schema.Initialize() 的第 328 行 in / /src/GraphQL/Types/Schema.cs: GraphQL.Utilities.SchemaPrinter.PrintFilteredSchema(Func 2 directiveFilter, Func2 typeFilter) in / /src/GraphQL/的第 102 行Utilities/SchemaPrinter.cs:GraphQL.Utilities.SchemaPrinter.Print() 中的第 79 行 //src/GraphQL/Utilities/SchemaPrinter.cs:位于 C:\ws\Autumn-APICore\Autumn.Api\Controllers\AutumnController.cs:Autumn.Api.Controllers.AutumnController.Schema() 的第 63 行:Microsoft 的第 37 行。 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());
        }
    }
}
4

1 回答 1

0

错误是不需要 AutumnQuery 并且在构造函数 IServiceProvider 中具有

于 2021-08-11T13:50:45.730 回答