Skip to content

Commit d78705d

Browse files
Cleanup
1 parent a8419f5 commit d78705d

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

Diff for: src/HotChocolate/Core/src/Types/SemanticNonNullTypeInterceptor.cs

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
using System.Collections;
44
using HotChocolate.Configuration;
5-
using HotChocolate.Execution.Processing;
65
using HotChocolate.Language;
76
using HotChocolate.Resolvers;
87
using HotChocolate.Types;
98
using HotChocolate.Types.Descriptors;
109
using HotChocolate.Types.Descriptors.Definitions;
1110
using HotChocolate.Types.Helpers;
12-
using HotChocolate.Types.Pagination;
1311
using HotChocolate.Types.Relay;
12+
using HotChocolate.Utilities;
1413

1514
namespace HotChocolate;
1615

@@ -347,7 +346,7 @@ private static void CheckResultForSemanticNonNullViolations(object? result, IRes
347346
{
348347
if (result is null && levels.Contains(currentLevel))
349348
{
350-
context.ReportError(CreateSemanticNonNullViolationError(path, context.Selection));
349+
context.ReportError(ErrorHelper.CreateSemanticNonNullViolationError(path, context.Selection));
351350
return;
352351
}
353352

@@ -368,13 +367,4 @@ private static void CheckResultForSemanticNonNullViolations(object? result, IRes
368367
}
369368
}
370369
}
371-
372-
// TODO: Move
373-
public static IError CreateSemanticNonNullViolationError(Path path, ISelection selection)
374-
=> ErrorBuilder.New()
375-
.SetMessage("Cannot return null for semantic non-null field.")
376-
.SetCode(ErrorCodes.Execution.SemanticNonNullViolation)
377-
.AddLocation(selection.SyntaxNode)
378-
.SetPath(path)
379-
.Build();
380370
}

Diff for: src/HotChocolate/Core/src/Types/Utilities/ErrorHelper.cs

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Globalization;
2+
using HotChocolate.Execution.Processing;
23
using HotChocolate.Language;
34
using HotChocolate.Properties;
45
using HotChocolate.Types;
@@ -538,4 +539,12 @@ public static ISchemaError DuplicateFieldName(
538539
.SetTypeSystemObject(type)
539540
.Build();
540541
}
542+
543+
public static IError CreateSemanticNonNullViolationError(Path path, ISelection selection)
544+
=> ErrorBuilder.New()
545+
.SetMessage("Cannot return null for semantic non-null field.")
546+
.SetCode(ErrorCodes.Execution.SemanticNonNullViolation)
547+
.AddLocation(selection.SyntaxNode)
548+
.SetPath(path)
549+
.Build();
541550
}

Diff for: src/HotChocolate/Fusion/src/Core/Execution/ExecutionUtils.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text.Json;
55
using HotChocolate.Execution.Processing;
66
using HotChocolate.Fusion.Execution.Nodes;
7+
using HotChocolate.Fusion.Execution.Pipeline;
78
using HotChocolate.Fusion.Metadata;
89
using HotChocolate.Fusion.Planning;
910
using HotChocolate.Fusion.Utilities;
@@ -12,6 +13,7 @@
1213
using HotChocolate.Types;
1314
using HotChocolate.Utilities;
1415
using static HotChocolate.Execution.Processing.Selection;
16+
using ErrorHelper = HotChocolate.Utilities.ErrorHelper;
1517
using IType = HotChocolate.Types.IType;
1618
using ObjectType = HotChocolate.Types.ObjectType;
1719

@@ -774,7 +776,7 @@ private static void AddSemanticNonNullViolation(
774776
int responseIndex)
775777
{
776778
var path = PathHelper.CreatePathFromContext(selection, selectionSetResult, responseIndex);
777-
var error = SemanticNonNullTypeInterceptor.CreateSemanticNonNullViolationError(path, selection);
779+
var error = ErrorHelper.CreateSemanticNonNullViolationError(path, selection);
778780
resultBuilder.AddError(error);
779781
}
780782

@@ -789,9 +791,6 @@ private static void PropagateNullValues(
789791
ValueCompletion.PropagateNullValues(selectionSetResult);
790792
}
791793

792-
// TODO: Pull out
793-
private const int MaxLevels = 3;
794-
795794
private static readonly CustomOptionsFlags[] _levelOptions =
796795
[
797796
CustomOptionsFlags.Option5,
@@ -801,7 +800,7 @@ private static void PropagateNullValues(
801800

802801
private static bool IsSemanticNonNull(Selection selection, int level)
803802
{
804-
if (level >= MaxLevels)
803+
if (level >= SemanticNonNullOptimizer.MaxLevels)
805804
{
806805
return true;
807806
}

Diff for: src/HotChocolate/Fusion/src/Core/Execution/Pipeline/SemanticNonNullOptimizer.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ namespace HotChocolate.Fusion.Execution.Pipeline;
44

55
internal sealed class SemanticNonNullOptimizer : ISelectionSetOptimizer
66
{
7-
// TODO: Pull this out to somewhere
8-
private const int MaxLevels = 3;
7+
// This is an arbitrary limit to only use the last three options,
8+
// so there's still room for other features requiring options.
9+
// This is not ideal, but acceptable as this is just a prototype.
10+
public const int MaxLevels = 3;
911

1012
private static readonly Selection.CustomOptionsFlags[] _levelOptions =
1113
[

Diff for: src/HotChocolate/Fusion/test/Core.Tests/SemanticNonNullTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
namespace HotChocolate.Fusion;
77

8-
// TODO: Test with list with more than 3 levels
9-
// TODO: What is supposed to happen with a non-null that bubbles up to a semantic non-null field?
108
public class SemanticNonNullTests(ITestOutputHelper output)
119
{
1210
# region Scalar

0 commit comments

Comments
 (0)