Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get MaxExecutionDepth option to work #1881

Closed
PrimeHydra opened this issue May 6, 2020 · 7 comments
Closed

Can't get MaxExecutionDepth option to work #1881

PrimeHydra opened this issue May 6, 2020 · 7 comments
Assignees
Labels
❓ question This issue is a question about feature of Hot Chocolate.

Comments

@PrimeHydra
Copy link

PrimeHydra commented May 6, 2020

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

@PrimeHydra PrimeHydra changed the title Can't get MaxQueryDepth option to work Can't get MaxExecutionDepth option to work May 6, 2020
@michaelstaib
Copy link
Member

Can you oath the options into usedefaultpipeline?

@michaelstaib michaelstaib self-assigned this May 6, 2020
@michaelstaib michaelstaib added 🌶 hot chocolate 🔍 investigate Indicates that an issue or pull request needs more information. labels May 6, 2020
@PrimeHydra
Copy link
Author

PrimeHydra commented May 6, 2020

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

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

@michaelstaib
Copy link
Member

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.

@PrimeHydra
Copy link
Author

@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?

@michaelstaib
Copy link
Member

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.

@PrimeHydra
Copy link
Author

That works--thank you for the quick response!

@michaelstaib
Copy link
Member

Great, I am closing the issue.

@michaelstaib michaelstaib added ❓ question This issue is a question about feature of Hot Chocolate. and removed 🔍 investigate Indicates that an issue or pull request needs more information. labels May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question This issue is a question about feature of Hot Chocolate.
Projects
None yet
Development

No branches or pull requests

2 participants