1
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.
4
2 Answers
Reset to default
2
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>();
0
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
Not the answer you're looking for? Browse other questions tagged
or ask your own question.
or ask your own question.
Have you tried to move use setting in the
Create
callMay 6, 2020 at 14:26
@GuruStron not sure what you mean;
Create()
takes no params.May 6, 2020 at 14:28
Oh, i misread API, sorry.
May 6, 2020 at 14:29
Added a answer, please try it out.
May 6, 2020 at 14:44
|