Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Fusion Non-Null propagation #7011

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static partial class ValueCompletion
{
return null;
}

var elementType = type.InnerType();
var isLeafType = elementType.IsLeafType();
var operationContext = context.OperationContext;
Expand Down Expand Up @@ -103,7 +103,7 @@ internal static partial class ValueCompletion
{
resultList.Grow();
}

if (!TryCompleteElement(context, selection, elementType, isLeafType, resultList, i++, element))
{
operationContext.Result.AddRemovedResult(resultList);
Expand Down Expand Up @@ -148,12 +148,12 @@ private static bool TryCompleteElement(
{
return list.IsNullable;
}

list.SetUnsafe(index, resultData);
}
return true;
}

return list.IsNullable;
}

Expand All @@ -163,14 +163,14 @@ internal static void PropagateNullValues(ResultData result)
{
return;
}

result.IsInvalidated = true;

while (result.Parent is not null)
{
var index = result.ParentIndex;
var parent = result.Parent;

if(parent.IsInvalidated)
{
return;
Expand All @@ -186,7 +186,7 @@ internal static void PropagateNullValues(ResultData result)
}
objectResult.IsInvalidated = true;
break;

case ListResult listResult:
if (listResult.TrySetNull(index))
{
Expand All @@ -195,8 +195,8 @@ internal static void PropagateNullValues(ResultData result)
listResult.IsInvalidated = true;
break;
}

result = parent;
}
}
}
}
32 changes: 20 additions & 12 deletions src/HotChocolate/Fusion/src/Core/Execution/ExecutorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using HotChocolate.Language;
using HotChocolate.Types;
using static HotChocolate.Execution.Processing.Selection;
using static HotChocolate.Execution.Processing.ValueCompletion;
using IType = HotChocolate.Types.IType;
using ObjectType = HotChocolate.Types.ObjectType;

Expand Down Expand Up @@ -68,7 +67,7 @@
{
if (!nullable)
{
PropagateNullValues(selectionSetResult);
PropagateNullValues(context.Result, selection, selectionSetResult, responseIndex);
break;
}

Expand All @@ -79,10 +78,9 @@
{
var value = data.Single.Element;

if (value.ValueKind is JsonValueKind.Null or JsonValueKind.Undefined &&
!nullable)
if (value.ValueKind is JsonValueKind.Null or JsonValueKind.Undefined && !nullable)
{
PropagateNullValues(selectionSetResult);
PropagateNullValues(context.Result, selection, selectionSetResult, responseIndex);
break;
}

Expand All @@ -104,7 +102,7 @@
if (value.ValueKind is JsonValueKind.Null or JsonValueKind.Undefined &&
!nullable)
{
PropagateNullValues(selectionSetResult);
PropagateNullValues(context.Result, selection, selectionSetResult, responseIndex);

Check warning on line 105 in src/HotChocolate/Fusion/src/Core/Execution/ExecutorUtils.cs

View check run for this annotation

Codecov / codecov/patch

src/HotChocolate/Fusion/src/Core/Execution/ExecutorUtils.cs#L105

Added line #L105 was not covered by tests
break;
}

Expand All @@ -123,7 +121,7 @@

if (value is null && !nullable)
{
PropagateNullValues(selectionSetResult);
PropagateNullValues(context.Result, selection, selectionSetResult, responseIndex);
break;
}

Expand All @@ -144,7 +142,7 @@

if (value is null && !nullable)
{
PropagateNullValues(selectionSetResult);
PropagateNullValues(context.Result, selection, selectionSetResult, responseIndex);
break;
}

Expand Down Expand Up @@ -216,7 +214,7 @@

if (!nullable && element is null)
{
PropagateNullValues(result);
PropagateNullValues(context.Result, selection, result, index);
return null;
}

Expand Down Expand Up @@ -495,14 +493,13 @@
var path = PathHelper.CreatePathFromContext(selectionSetResult);
foreach (var error in errors.EnumerateArray())
{
ExtractError(resultBuilder, error, selectionSetResult, path, pathDepth, addDebugInfo);
ExtractError(resultBuilder, error, path, pathDepth, addDebugInfo);
}
}

private static void ExtractError(
ResultBuilder resultBuilder,
JsonElement error,
ObjectResult selectionSetResult,
Path parentPath,
int pathDepth,
bool addDebugInfo)
Expand Down Expand Up @@ -538,7 +535,7 @@
{
var path = PathHelper.CombinePath(parentPath, remotePath, pathDepth);
errorBuilder.SetPath(path);

if (addDebugInfo)
{
errorBuilder.SetExtension("remotePath", remotePath);
Expand Down Expand Up @@ -642,4 +639,15 @@
}
}
}

private static void PropagateNullValues(
ResultBuilder resultBuilder,
Selection selection,
ResultData selectionSetResult,
int responseIndex)
{
var path = PathHelper.CreatePathFromContext(selection, selectionSetResult, responseIndex);
resultBuilder.AddNonNullViolation(selection, path);
ValueCompletion.PropagateNullValues(selectionSetResult);
}
}
17 changes: 0 additions & 17 deletions src/HotChocolate/Fusion/src/Core/Execution/Nodes/QueryPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,6 @@ public async Task<IQueryResult> ExecuteAsync(
{
await RootNode.ExecuteAsync(context, cancellationToken).ConfigureAwait(false);
}
catch (NonNullPropagateException ex)
{
context.Result.SetData(null);

// TODO : REMOVE after non-null prop is good.
if (context.Result.Errors.Count == 0)
{
var error =
context.OperationContext.ErrorHandler.Handle(
ErrorBuilder.New()
.SetMessage("NON NULL PROPAGATION")
.SetException(ex)
.Build());

context.Result.AddError(error);
}
}
catch (Exception ex)
{
if (context.Result.Errors.Count == 0)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,78 @@ query ReformatIds {
```json
{
"errors": [
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
3,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
2,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
1,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
0,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Internal Execution Error"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,78 @@ query ReformatIds {
```json
{
"errors": [
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
3,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
2,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
1,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Cannot return null for non-nullable field.",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"reviews",
0,
"author",
"birthdate"
],
"extensions": {
"code": "HC0018"
}
},
{
"message": "Internal Execution Error"
}
Expand Down
Loading
Loading