0

我正在使用 .net 5.0 创建一个 Graphql.net 4.7.1 应用程序。在我的 GraphQLController 中执行这样的虚拟查询;

 var result = await _executer.ExecuteAsync(_ =>
            {
                _.Schema = Schema.For(@"
                              type Query {
                                hello: String
                              }
                            ");
                _.Query = "{hello}";
                _.OperationName = null; 

            }).ConfigureAwait(false);

当我检查结果时,它没有数据;

在此处输入图像描述

但是,我使用 Graphql.net 2.4 的原始应用程序返回了正确的结果,例如;

在此处输入图像描述

如何解决?

包裹如下;

 <PackageReference Include="GraphQL.DataLoader" Version="4.7.1" />
    <PackageReference Include="GraphQL.MicrosoftDI" Version="4.7.1" />
    <PackageReference Include="GraphQL.NewtonsoftJson" Version="4.7.1" />
    <PackageReference Include="GraphQL.Server.Ui.Playground" Version="3.4.0" />
    <PackageReference Include="GraphQL" Version="4.7.1" />    
    <PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="4.0.1" />    
    <PackageReference Include="GraphQL.SystemTextJson" Version="4.7.1" />    
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.14" />       
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.6">

如下所示的配置服务;

           services.AddDbContext<DatabaseContext>(options =>
            {
                options.UseNpgsql(_connectionString);
            });
            services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));
            services.AddScoped<IFieldService, FieldService>();

            services.AddScoped<MainMutation>();
            services.AddScoped<MainQuery>();
            services.AddScoped<RestaurantGType>();
            services.AddScoped<TagGType>();
            services.AddScoped<FoodSchema>();
            services.AddScoped<IDataLoaderContextAccessor, DataLoaderContextAccessor>();
            services.AddScoped<DataLoaderDocumentListener>();
            services.AddGraphQL()                
              .AddGraphTypes(ServiceLifetime.Scoped);

            services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
                                              .AllowAnyMethod()
                                               .AllowAnyHeader()));

            services.AddControllers()
                .AddNewtonsoftJson(options =>
                       options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                );
4

0 回答 0