【问题标题】:GraphQL for .NET core 3.1.NET 核心 3.1 的 GraphQL
【发布时间】:2021-08-20 17:08:05
【问题描述】:

我是 .NET 核心的 GraphQL 新手。 我在源代码中添加了 GraphQL,但在调试时未添加到控制器中。它去了我的 ObjectGrapType 查看图片详情:

  1. 在 GrapiQL 中单击开始 enter image description here
  2. 然后它不去控制器 enter image description here 3.进入订单查询 enter image description here

我不明白为什么会这样

你能不能帮我检查一下。 这是一个错误吗? 我的创业班:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddDiscoveryClient(Configuration);
        services.AddCustomDbContext(Configuration);
        services.AddControllers()
            .AddNewtonsoftJson(o => o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
        services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
        services.AddCustomSwagger();

        services.AddCustomDependency(Configuration);
    }

    // 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.UseDiscoveryClient();

        // Enable middleware to serve generated Swagger as a JSON endpoint.
        app.UseSwagger();
        // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
        // specifying the Swagger JSON endpoint.
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
        });
        app.UseGraphiQl("/graphql");
        app.UseRouting();

        app.UseAuthorization();
        app.UseGraphQL<OrderQuerySchema>();
        app.UseGraphQLPlayground(options: new GraphQLPlaygroundOptions());
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }

非常感谢,祝你有美好的一天

LamNV

【问题讨论】:

    标签: c# asp.net-core controller graphql


    【解决方案1】:

    没听懂。你使用什么库 - GraphQL.Net? 顺便说一句,基于 GraphQL.net 存在一个更优雅的解决方案,可以更轻松地启动。您只需在 JSON 文件中定义模式并设置 DB 连接字符串 (NReco.GraphQL)

    【讨论】:

      猜你喜欢
      • 2022-07-08
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 2020-05-25
      相关资源
      最近更新 更多