ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.23k stars 744 forks source link

Query Plan in Hot Chocolate 12-preview.16 has issues detecting parallel and serial execution attributes. #3848

Closed munkhnasanHUB closed 3 years ago

munkhnasanHUB commented 3 years ago

Startup:

public class Startup
    {
        private readonly IWebHostEnvironment _env;
        public Startup(IConfiguration configuration, IWebHostEnvironment env)
        {
            Configuration = configuration;
            _env = env;
        }
        public IConfiguration Configuration { get; }
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddCors()
                .AddScoped<SharedRepository>()
                .AddDbContext<SisiDBContext>(
                    (services, options) => options
                        .UseSqlServer(Configuration.GetConnectionString("sisiGraphQLDBConnection"))
                        .UseLoggerFactory(services.GetRequiredService<ILoggerFactory>()))
                .AddGraphQLServer()
                .AddQueryType(d => d.Name("Query"))
                    .AddTypeExtension<SharedQueries>()
                .AddTypeExtension<TbTpAcademiclevelDetails>()
                .AddProjections()
                .AddFiltering()
                .AddSorting()
                .ModifyOptions(o => o.DefaultResolverStrategy = ExecutionStrategy.Serial)
                .ModifyRequestOptions(opt => opt.IncludeExceptionDetails = _env.IsDevelopment());
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseCors(o => o
                .AllowAnyHeader()
                .AllowAnyMethod()
                .AllowAnyOrigin());
            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGraphQL();
            });
        }
    }

Query:

[ExtendObjectType("Query")]
    public class SharedQueries
    {
        [Parallel] //not working
        [UseProjection]
        [GraphQLDescription("бүх академик түвшний жагсаалт")]
        [GraphQLName("academicLevels")]
        public IQueryable<TbTpAcademiclevel> GetAcademiclevels(
            [Service] SisiDBContext dbContext) =>
            dbContext.TbTpAcademiclevels;

        [UseFirstOrDefault] //not working
        [UseProjection]
        [GraphQLDescription("академик түвшин")]
        [GraphQLName("academicLevelByID")]
        public IQueryable<TbTpAcademiclevel> GetAcademiclevelByIdAsync(
            byte id,
            [Service] SisiDBContext dbContext) =>
            dbContext.TbTpAcademiclevels.Where(a => a.RecNr == id);

        [UseProjection]
        [GraphQLDescription("Хичээлийн жил")]
        [GraphQLName("academicYears")]
        public IQueryable<TbAcademicYear> GetAcademicYears([Service] SharedRepository sharedRepository)
        {
            return sharedRepository.GetAcademicYears();
        }
    }

ExtendObjectType:

[ExtendObjectType(typeof(TbTpAcademiclevel))]
    public class TbTpAcademiclevelDetails
    {
        [Serial] //not working
        [GraphQLName("test1")]
        public string GetTest1(
           [Parent] TbTpAcademiclevel academiclevel)
        {
            return academiclevel.Alevelm + " test1";
        }

        [Serial] //not working
        [GraphQLName("test2")]
        public string GetTest2(
           [Parent] TbTpAcademiclevel academiclevel)
        {
            return academiclevel.Alevel + " test2";
        }
    }
  1. [ExtendObjectType(typeof(TbTpAcademiclevel))] [Serial] is not working
  2. When i use .ModifyOptions(o => o.DefaultResolverStrategy = ExecutionStrategy.Serial) SharedQueries's all queries strategy is Serial. But [Parallel] strategy is not working.
  3. [UseFirstOrDefault] isn't work v12-preview.16 when I use Mssql in Parallel strategy
michaelstaib commented 3 years ago
michaelstaib commented 3 years ago

[UseFirstOrDefault] isn't work v12-preview.16 when I use Mssql in Parallel strategy

If you apply this on EF core than it must be used in serial context.