Reputation: 1770
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.
Upvotes: 1
Views: 1742
Reputation: 1819
Since the original question and answer are more than 3 years old, so for anyone else like myself who ran into this issue now, this is another option (V13 of HotChocolate):
In your Program.cs
modify the GraphQl server section like this and add AddMaxExecutionDepthRule
:
builder.Services.AddGraphQLServer()
.AddQueryType<GraphQlQuery>()
.AddProjections()
.AddFiltering()
.AddSorting()
.AddMaxExecutionDepthRule(5);
Here 5 (or any other number) is the depth that you want.
Reference: https://chillicream.com/docs/hotchocolate/v13/security#execution-depth
Upvotes: 2
Reputation: 1770
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>();
Upvotes: 2