Skip to content

Commit 886b3fb

Browse files
Proper Invalidation handling
1 parent 9cab874 commit 886b3fb

File tree

4 files changed

+34
-53
lines changed

4 files changed

+34
-53
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/OperationPlanContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ internal IOperationResult Complete()
144144

145145
var result = resultBuilder
146146
.AddErrors(_resultStore.Errors)
147-
.SetData(_resultStore.Data)
147+
.SetData(_resultStore.Data.IsInvalidated ? null : _resultStore.Data)
148148
.RegisterForCleanup(_resultStore.MemoryOwners)
149149
.RegisterForCleanup(_resultPoolSessionHolder)
150150
.Build();

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/Results/FetchResultStore.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,20 @@ public bool AddErrors(ReadOnlySpan<SourceSchemaError> errors, ReadOnlySpan<strin
130130

131131
while (Unsafe.IsAddressLessThan(ref error, ref end))
132132
{
133-
if (error.Path.IsRoot)
133+
if (_root.IsInvalidated)
134134
{
135-
if (!_valueCompletion.BuildResult(_root, responseNames, error))
136-
{
137-
// TODO: This is wrong
138-
_root = null!;
139-
return false;
140-
}
135+
return false;
141136
}
142-
else
137+
138+
var result = error.Path.IsRoot ? _root : GetStartObjectResult(error.Path);
139+
140+
if (result.IsInvalidated)
143141
{
144-
var startResult = GetStartObjectResult(error.Path);
145-
if (!_valueCompletion.BuildResult(startResult, responseNames, error))
146-
{
147-
// TODO: This is wrong
148-
_root = null!;
149-
return false;
150-
}
142+
continue;
151143
}
152144

145+
_valueCompletion.BuildResult(result, responseNames, error);
146+
153147
error = ref Unsafe.Add(ref error, 1)!;
154148
}
155149
}

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/Results/ResultData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public abstract class ResultData : IResultDataJsonFormatter
2121
/// </summary>
2222
protected internal int ParentIndex { get; private set; }
2323

24+
public bool IsInvalidated { get; set; }
25+
2426
/// <summary>
2527
/// Gets the path of the result.
2628
/// </summary>

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/Results/ValueCompletion.cs

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,9 @@ public bool BuildResult(
8080

8181
if (!TryCompleteValue(selection, selection.Type, element, errorTrieForResponseName, 0, fieldResult))
8282
{
83-
var parentIndex = fieldResult.ParentIndex;
84-
var parent = fieldResult.Parent;
85-
8683
if (_errorHandling is ErrorHandling.Propagate)
8784
{
88-
while (parent is not null)
89-
{
90-
if (parent.TrySetValueNull(parentIndex))
91-
{
92-
break;
93-
}
94-
else
95-
{
96-
parentIndex = parent.ParentIndex;
97-
parent = parent.Parent;
98-
99-
if (parent is null)
100-
{
101-
return false;
102-
}
103-
}
104-
}
105-
}
106-
else
107-
{
108-
fieldResult?.TrySetValueNull(parentIndex);
85+
PropagateNullValues(objectResult);
10986
}
11087
}
11188
}
@@ -114,7 +91,7 @@ public bool BuildResult(
11491
return true;
11592
}
11693

117-
public bool BuildResult(
94+
public void BuildResult(
11895
ObjectResult objectResult,
11996
ReadOnlySpan<string> responseNames,
12097
SourceSchemaError sourceSchemaError)
@@ -135,35 +112,43 @@ public bool BuildResult(
135112

136113
_errors.Add(error);
137114

138-
if (_errorHandling is ErrorHandling.Propagate)
115+
if (_errorHandling is ErrorHandling.Propagate && fieldResult.Selection.Type.IsNonNullType())
139116
{
140-
// TODO: We need an invalidated state for the resultdata
141-
if (!PropagateNullValues(fieldResult))
142-
{
143-
return false;
144-
}
117+
PropagateNullValues(objectResult);
118+
119+
return;
145120
}
146121
}
147-
148-
return true;
149122
}
150123

151-
private static bool PropagateNullValues(ResultData result)
124+
private static void PropagateNullValues(ResultData result)
152125
{
126+
if (result.IsInvalidated)
127+
{
128+
return;
129+
}
130+
131+
result.IsInvalidated = true;
132+
153133
while (result.Parent is not null)
154134
{
155135
var index = result.ParentIndex;
156136
var parent = result.Parent;
157137

138+
if (parent.IsInvalidated)
139+
{
140+
return;
141+
}
142+
158143
if (parent.TrySetValueNull(index))
159144
{
160-
return true;
145+
return;
161146
}
162147

148+
parent.IsInvalidated = true;
149+
163150
result = parent;
164151
}
165-
166-
return false;
167152
}
168153

169154
private bool TryCompleteValue(

0 commit comments

Comments
 (0)