热巧克力模式无加载

Hot Chocolate Schema no Loading

我正在尝试使用 Hot Chocolate 12.3.2 在 .NET 中实现 GraphQL API。我能够构建项目并 运行。尝试测试我的查询 CakePop 时,浏览器加载正常,但不存在架构。

startup.cs

namespace Application
{
  public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    [Obsolete]
    public void ConfigureServices(IServiceCollection services)
        {
            services.AddGraphQLServer()
                    .AddQueryType<Query>()
                    .AddType<BillType>().AddGraphQL()
                    .BindRuntimeType<DateOnly, DateType>()
                    .AddTypeConverter<DateOnly, DateTime>(from => DateTime.Parse(from.ToString()))
                    .AddTypeConverter<DateTime, DateOnly>(from => DateOnly.FromDateTime(from));
            services.AddGraphQL(sp => SchemaBuilder.New().AddServices(sp).Create())
                            .AddPooledDbContextFactory<WeVoteContext>(b =>b.UseInMemoryDatabase("Test"));
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app
                .UseRouting()
                .UseEndpoints(endpoints =>
                {
                  endpoints.MapGraphQL().WithOptions(new GraphQLServerOptions
                  {
                        EnableSchemaRequests = true,
                        Tool = {
                            Enable = env.IsDevelopment()
                        }
                  });
                });
        }
    }
}

query.cs

namespace Application
{
  public class Query
  {
    static ApplicationContext db = new ApplicationContext();
    public IEnumerable<LegiscanModelBill> GetBills(int N)
    {
      return db.LegiscanModelBills.Take(N).AsEnumerable();
    }

  }
}

Models/LegiscanModelBill.cs

namespace Application.Models
{
  public partial class LegiscanModelBill
    {
        [GraphQLIgnore]
        public int Id { get; set; }
        public string? BillNumber { get; set; }
        public string? ChangeHash { get; set; }
        public string? Url { get; set; }

        [GraphQLIgnore]
        public DateOnly? StatusDate { get; set; }
        public int? StatusId { get; set; }

        [GraphQLIgnore]
        public DateOnly? LastActionDate { get; set; }
        public string? LastAction { get; set; }
        public string? Title { get; set; }
        public string? Description { get; set; }
        [GraphQLIgnore]
        public DateTime CreatedAt { get; set; }
        [GraphQLIgnore]
        public DateTime UpdatedAt { get; set; }
        public int? SessionId { get; set; }
        public int? UpvotesCount { get; set; }
        public int? BodyId { get; set; }
        public DateTime? LegiscanDataUpdatedAt { get; set; }
        public int? BillId { get; set; }
        public int? CommentsCount { get; set; }
        public double? Hotness { get; set; }
        public string? Texts { get; set; }
        public int? CommitteeId { get; set; }
        public int? BillTypeId { get; set; }
        public string? StateLink { get; set; }
    }

  public class BillType : ObjectType<LegiscanModelBill>
  {

  }
}

日志中没有任何内容

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development

更新服务

        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddPooledDbContextFactory<WeVoteContext>(b => b.UseInMemoryDatabase("Test"))
                .AddGraphQLServer()
                .AddQueryType<Query>()
                .AddType<BillType>();
            // .BindRuntimeType<DateOnly, DateType>()
            // .AddTypeConverter<DateOnly, DateTime>(from => from.ToDateTime(default))
            // .AddTypeConverter<DateTime, DateOnly>(from => DateOnly.FromDateTime(from.Date));
        }

设置代码似乎有问题...您正在混合旧配置 API 和新配置 API。

services
    .AddPooledDbContextFactory<WeVoteContext>(b =>b.UseInMemoryDatabase("Test"))
    .AddGraphQLServer()
    .AddQueryType<Query>()
    .AddType<BillType>()
    .BindRuntimeType<DateOnly, DateType>()
    .AddTypeConverter<DateOnly, DateTime>(from => from.ToDateTime(default))
    .AddTypeConverter<DateTime, DateOnly>(from => DateOnly.FromDateTime(from.Date));

我们在 12.4.0-preview.8 中提供了对 TimeOnlyDateOnly 的支持。

当您移动到 ​​12.4 时删除显式绑定和转换器。

此外,您可以再次使用此配置删除 GraphQLIgnore 属性。