Skip to content

Commit

Permalink
Fixed Validation Resources (#2642)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Nov 22, 2020
1 parent 7b76d57 commit 4844fdc
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 49 deletions.
31 changes: 0 additions & 31 deletions src/HotChocolate/Core/benchmark/Execution.Benchmarks/Program.cs
Expand Up @@ -9,36 +9,5 @@ class Program
{
static void Main(string[] args) =>
BenchmarkRunner.Run(typeof(Program).Assembly);

/*
static async Task Main(string[] args)
{
var bench = new DefaultExecutionPipelineBenchmark();
for (int i = 0; i < 1000; i++)
{
Console.WriteLine("starting " + i);
var time = Stopwatch.StartNew();
await bench.SchemaIntrospection();
Console.WriteLine("finished " + i + " " + time.Elapsed);
}
for (int i = 0; i < 1000; i++)
{
Console.WriteLine("starting " + i);
var time = Stopwatch.StartNew();
await bench.GetHero();
Console.WriteLine("finished " + i + " " + time.Elapsed);
}
for (int i = 0; i < 50; i++)
{
Console.WriteLine("starting " + i);
var time = Stopwatch.StartNew();
await bench.GetHeroWithFriendsFiveParallelRequests();
Console.WriteLine("finished " + i + " " + time.Elapsed);
}
}
*/
}
}
16 changes: 16 additions & 0 deletions src/HotChocolate/Core/src/Validation/ErrorHelper.cs
Expand Up @@ -590,5 +590,21 @@ internal static class ErrorHelper
.SetExtension("detectedComplexity", detectedComplexity)
.Build();
}

public static IError MaxExecutionDepth(
this IDocumentValidatorContext context,
OperationDefinitionNode operation,
int allowedExecutionDepth,
int detectedExecutionDepth)
{
return ErrorBuilder.New()
.SetMessage(
Resources.ErrorHelper_MaxExecutionDepth,
detectedExecutionDepth, allowedExecutionDepth)
.AddLocation(operation)
.SetExtension("allowedExecutionDepth", allowedExecutionDepth)
.SetExtension("detectedExecutionDepth", detectedExecutionDepth)
.Build();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -206,6 +206,9 @@
<data name="ErrorHelper_MaxOperationComplexity" xml:space="preserve">
<value>The GraphQL document has an operation complexity of {0} which exceeds the max allowed operation complexity of {1}.</value>
</data>
<data name="ErrorHelper_MaxExecutionDepth" xml:space="preserve">
<value>The GraphQL document has an execution depth of {0} which exceeds the max allowed execution depth of {1}.</value>
</data>
<data name="HotChocolateValidationBuilderExtensions_MinimumAllowedValue" xml:space="preserve">
<value>The minimum allowed value is 1.</value>
</data>
Expand Down
Expand Up @@ -30,7 +30,7 @@ public MaxExecutionDepthVisitor(IMaxExecutionDepthOptionsAccessor options)
if (_options.MaxAllowedExecutionDepth.HasValue &&
_options.MaxAllowedExecutionDepth < context.Max)
{
context.Errors.Add(context.MaxOperationComplexity(
context.Errors.Add(context.MaxExecutionDepth(
node, _options.MaxAllowedExecutionDepth.Value, context.Max));
return Break;
}
Expand Down
@@ -1,16 +1,16 @@
{
"errors": [
{
"message": "The GraphQL document has an operation complexity of 6 which exceeds the max allowed operation complexity of 3.",
"message": "The GraphQL document has an execution depth of 6 which exceeds the max allowed execution depth of 3.",
"locations": [
{
"line": 2,
"column": 17
}
],
"extensions": {
"allowedComplexity": 3,
"detectedComplexity": 6
"allowedExecutionDepth": 3,
"detectedExecutionDepth": 6
}
}
]
Expand Down
Expand Up @@ -624,8 +624,8 @@ public void MaxDepthRuleIsIncluded()
t =>
{
Assert.Equal(
"The GraphQL document has an operation complexity of 2 " +
"which exceeds the max allowed operation complexity of 1.",
"The GraphQL document has an execution depth of 2 " +
"which exceeds the max allowed execution depth of 1.",
t.Message);
});
}
Expand Down
@@ -1,6 +1,6 @@
[
{
"Message": "The GraphQL document has an operation complexity of 2 which exceeds the max allowed operation complexity of 1.",
"Message": "The GraphQL document has an execution depth of 2 which exceeds the max allowed execution depth of 1.",
"Code": null,
"Path": null,
"Locations": [
Expand All @@ -10,8 +10,8 @@
}
],
"Extensions": {
"allowedComplexity": 1,
"detectedComplexity": 2
"allowedExecutionDepth": 1,
"detectedExecutionDepth": 2
},
"Exception": null
}
Expand Down
@@ -1,6 +1,6 @@
[
{
"Message": "The GraphQL document has an operation complexity of 4 which exceeds the max allowed operation complexity of 3.",
"Message": "The GraphQL document has an execution depth of 4 which exceeds the max allowed execution depth of 3.",
"Code": null,
"Path": null,
"Locations": [
Expand All @@ -10,8 +10,8 @@
}
],
"Extensions": {
"allowedComplexity": 3,
"detectedComplexity": 4
"allowedExecutionDepth": 3,
"detectedExecutionDepth": 4
},
"Exception": null
}
Expand Down
@@ -1,6 +1,6 @@
[
{
"Message": "The GraphQL document has an operation complexity of 4 which exceeds the max allowed operation complexity of 3.",
"Message": "The GraphQL document has an execution depth of 4 which exceeds the max allowed execution depth of 3.",
"Code": null,
"Path": null,
"Locations": [
Expand All @@ -10,8 +10,8 @@
}
],
"Extensions": {
"allowedComplexity": 3,
"detectedComplexity": 4
"allowedExecutionDepth": 3,
"detectedExecutionDepth": 4
},
"Exception": null
}
Expand Down
@@ -1,6 +1,6 @@
[
{
"Message": "The GraphQL document has an operation complexity of 4 which exceeds the max allowed operation complexity of 3.",
"Message": "The GraphQL document has an execution depth of 4 which exceeds the max allowed execution depth of 3.",
"Code": null,
"Path": null,
"Locations": [
Expand All @@ -10,8 +10,8 @@
}
],
"Extensions": {
"allowedComplexity": 3,
"detectedComplexity": 4
"allowedExecutionDepth": 3,
"detectedExecutionDepth": 4
},
"Exception": null
}
Expand Down

0 comments on commit 4844fdc

Please sign in to comment.