首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置GraphQL.net

设置GraphQL.net
EN

Stack Overflow用户
提问于 2021-08-10 20:26:41
回答 1查看 565关注 0票数 0

无法让它运行。我得到以下错误消息,我已经使它尽可能简单,但什么是必需的服务,我错过了。

我正在使用图类型第一方法。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(Func2 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[]参数)

代码语言:javascript
复制
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());
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-11 13:50:45

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68733119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档