Skip to content

Commit a869df6

Browse files
authored
Reset requirements planner for every iteration. (#7129)
1 parent 409f5e7 commit a869df6

File tree

13 files changed

+148
-110
lines changed

13 files changed

+148
-110
lines changed

src/HotChocolate/Core/src/Execution/Processing/SelectionSet.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Runtime.InteropServices;
4+
using System.Security;
5+
using System.Text;
6+
using HotChocolate.Types;
47

58
namespace HotChocolate.Execution.Processing;
69

@@ -11,7 +14,7 @@ namespace HotChocolate.Execution.Processing;
1114
/// </summary>
1215
internal sealed class SelectionSet : ISelectionSet
1316
{
14-
private static readonly Fragment[] _empty = Array.Empty<Fragment>();
17+
private static readonly Fragment[] _empty = [];
1518
private readonly Selection[] _selections;
1619
private readonly Fragment[] _fragments;
1720
private Flags _flags;
@@ -100,4 +103,39 @@ private enum Flags
100103
Conditional = 1,
101104
Sealed = 2,
102105
}
106+
107+
public override string ToString()
108+
{
109+
// this produces the rough structure of the selection set for debugging purposes.
110+
111+
var sb = new StringBuilder();
112+
113+
foreach (var selection in _selections)
114+
{
115+
if (selection.Type.IsLeafType())
116+
{
117+
if (selection.ResponseName.Equals(selection.Field.Name))
118+
{
119+
sb.AppendLine(selection.ResponseName);
120+
}
121+
else
122+
{
123+
sb.AppendLine($"{selection.ResponseName}: {selection.Field.Name}");
124+
}
125+
}
126+
else
127+
{
128+
if (selection.ResponseName.Equals(selection.Field.Name))
129+
{
130+
sb.AppendLine($"{selection.ResponseName} {{ ... }}");
131+
}
132+
else
133+
{
134+
sb.AppendLine($"{selection.ResponseName}: {selection.Field.Name} {{{{ ... }}}}");
135+
}
136+
}
137+
}
138+
139+
return sb.ToString();
140+
}
103141
}

src/HotChocolate/Fusion/src/Core/Planning/Pipeline/RequirementsPlannerMiddleware.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private static void Plan(QueryPlanContext context)
3333
continue;
3434
}
3535

36+
schemas.Clear();
3637
siblingsToRemove.Clear();
3738
roots.Clear();
3839

src/HotChocolate/Fusion/src/Core/Planning/QueryPlanContext.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ internal sealed class QueryPlanContext(IOperation operation)
1111
{
1212
private readonly Dictionary<ExecutionStep, QueryPlanNode> _stepToNode = new();
1313
private readonly Dictionary<QueryPlanNode, ExecutionStep> _nodeToStep = new();
14-
private readonly Dictionary<object, SelectionExecutionStep> _selectionLookup = new();
14+
private readonly Dictionary<ISelection, SelectionExecutionStep> _selectionLookup = new();
15+
private readonly Dictionary<ISelectionSet, SelectionExecutionStep> _selectionSetLookup = new();
1516
private readonly HashSet<ISelectionSet> _selectionSets = [];
1617
private readonly HashSet<ExecutionStep> _completed = [];
1718
private readonly string _opName = operation.Name ?? CreateOperationName(operation);
@@ -111,26 +112,29 @@ public bool TryGetExecutionStep(
111112
{
112113
ArgumentNullException.ThrowIfNull(selectionSet);
113114

114-
return _selectionLookup.TryGetValue(selectionSet, out step);
115+
return _selectionSetLookup.TryGetValue(selectionSet, out step);
115116
}
116117

117118
public void ReBuildSelectionLookup()
118119
{
119120
_selectionLookup.Clear();
121+
_selectionSetLookup.Clear();
120122

121123
foreach (var executionStep in Steps)
122124
{
123-
if (executionStep is SelectionExecutionStep ses)
125+
if (executionStep is not SelectionExecutionStep selectionStep)
124126
{
125-
foreach (var selection in ses.AllSelections)
126-
{
127-
_selectionLookup.TryAdd(selection, ses);
128-
}
129-
130-
foreach (var selectionSet in ses.AllSelectionSets)
131-
{
132-
_selectionLookup.TryAdd(selectionSet, ses);
133-
}
127+
continue;
128+
}
129+
130+
foreach (var selection in selectionStep.AllSelections)
131+
{
132+
_selectionLookup.TryAdd(selection, selectionStep);
133+
}
134+
135+
foreach (var selectionSet in selectionStep.AllSelectionSets)
136+
{
137+
_selectionSetLookup.TryAdd(selectionSet, selectionStep);
134138
}
135139
}
136140
}

src/HotChocolate/Fusion/test/Core.Tests/DataTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ query GetUser {
5757

5858
// assert
5959
var snapshot = new Snapshot();
60-
CollectSnapshotData(snapshot, request, result, fusionGraph);
60+
CollectSnapshotData(snapshot, request, result);
6161
await snapshot.MatchMarkdownAsync();
6262

6363
Assert.Null(result.ExpectQueryResult().Errors);

0 commit comments

Comments
 (0)