簡體   English   中英

熱巧克力模式沒有加載

[英]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屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM