Hotchocolate: Can't get MaxExecutionDepth option to work

Created on 6 May 2020  ·  7Comments  ·  Source: ChilliCream/hotchocolate

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()
                        .AddOptions(
                            new QueryExecutionOptions()
                            {
                                MaxExecutionDepth = 15
                            }))
            .Schema);

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

Also made an SO post. The answer suggesting I move the options inside UseDefaultPipeline() did not work.

Posted in the Slack yesterday but no response; figured I should post an issue instead.

HC version: 10.4.0
Edit: Also occurring in 10.4.3

❓ question 🌶 hot chocolate

All 7 comments

Can you oath the options into usedefaultpipeline?

Moving the options inside UseDefaultPipeline() did not work. (See SO post)

Or did you mean something else? Sorry if I misunderstand you.

I see the problem I think ...

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

try this.

@michaelstaib that took care of the execution depth, but my example was simplified; in reality, we also need some custom error filters like so:

            // 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);

How can I get the error filter registered as well?

Error filters can be added through dependency injection. We are refining the api for 11 so that it becomes easier to configure.

There are extension methods for error filters on service collection.

That works--thank you for the quick response!

Great, I am closing the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sascha-andres picture sascha-andres  ·  4Comments

benmccallum picture benmccallum  ·  5Comments

mortzi picture mortzi  ·  4Comments

nigel-sampson picture nigel-sampson  ·  5Comments

jbray1982 picture jbray1982  ·  5Comments