Search code examples
c#.net-coregraphqlhotchocolate

Hot Chocolate GraphQL - MaxExecutionDepth not working


How do I get MaxExecutionDepth to work in Hot Chocolate GraphQL? Here is my code:

    // Add GraphQL Services
    services.AddGraphQL(
        SchemaBuilder.New()
            // enable for authorization support
            .AddAuthorizeDirectiveType()
            .ModifyOptions(o => o.RemoveUnreachableTypes = true)
            .Create()
            .MakeExecutable(
                builder =>
                    builder
                        .UseDefaultPipeline()
                        .AddErrorFilter<UseExceptionMessageErrorFilter>()
                        .AddOptions(
                            new QueryExecutionOptions()
                            {
                                MaxExecutionDepth = 15
                            }))
            .Schema);

I've tested with this, even changing MaxExecutionDepth to 1, but I can still execute 20+ deep queries.


Solution

  • Per the developer in the GitHub issue I created, was able to get it working like this:

                services.AddGraphQL(
                    SchemaBuilder.New()
                        // enable for authorization support
                        .AddAuthorizeDirectiveType()
                        .ModifyOptions(o => o.RemoveUnreachableTypes = true)
                        .Create(),
                    new QueryExecutionOptions()
                    {
                        MaxExecutionDepth = ApiConfigurationConstants.MaxExecutionDepth
                    });
                services.AddErrorFilter<UseExceptionMessageErrorFilter>();