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
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.