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

[Fusion vNext] Add more tests and fix minor issues #7814

Merged
merged 1 commit into from
Dec 11, 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 @@ -135,7 +135,7 @@ private void InlineFragmentDefinition(
{
var fragmentContext = context.Branch(typeCondition);

RewriteFields(fragmentDefinition.SelectionSet, context);
RewriteFields(fragmentDefinition.SelectionSet, fragmentContext);

var selectionSet = new SelectionSetNode(
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public bool RemoveDirective(CompositeDirective directive)

private void InitializeConditions()
{
if(_isConditional.HasValue)
if (_isConditional.HasValue)
{
return;
}
Expand All @@ -170,7 +170,7 @@ private void InitializeConditions()
continue;
}

if (directive.Name.Value.Equals("skip"))
if (directive.Name.Value.Equals("include"))
{
_includeVariable = GetVariableName(directive);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RequestPlanNode CreatePlan(DocumentNode document, string? operationName)
var context = new PlaningContext(operation, operation, ImmutableStack<SelectionPathSegment>.Empty);
if (TryPlanSelectionSet(context))
{
PlanConditionNode(operation, operation.Selections);
TryMakeOperationConditional(operation, operation.Selections);
operationPlan.AddOperation(operation);
}
}
Expand Down Expand Up @@ -275,7 +275,7 @@ private bool TryHandleUnresolvedSelections(
}

schemasInContext.Add(schemaName, lookupOperation);
PlanConditionNode(lookupOperation, lookupField.Selections);
TryMakeOperationConditional(lookupOperation, lookupField.Selections);

// we add the lookup operation to all the schemas that we have requirements with.
foreach (var requiredSchema in fieldSchemaDependencies.Values.Distinct())
Expand Down Expand Up @@ -607,7 +607,7 @@ private static FieldNode CreateFieldNodeFromPath(FieldPath path)
return current!;
}

private void PlanConditionNode(
private void TryMakeOperationConditional(
OperationPlanNode operation,
IReadOnlyList<SelectionPlanNode> selections)
{
Expand Down Expand Up @@ -655,9 +655,8 @@ private void PlanConditionNode(
}
}

private bool IsSelectionAlwaysSkipped(ISelectionNode selectionNode)
private static bool IsSelectionAlwaysSkipped(ISelectionNode selectionNode)
{
var selectionIsSkipped = false;
foreach (var directive in selectionNode.Directives)
{
var isSkipDirective = directive.Name.Value == "skip";
Expand All @@ -673,26 +672,19 @@ private bool IsSelectionAlwaysSkipped(ISelectionNode selectionNode)
{
if (booleanValueNode.Value && isSkipDirective)
{
selectionIsSkipped = true;
return true;
}
else if (!booleanValueNode.Value && isIncludedDirective)
{
selectionIsSkipped = true;
}
else

if (!booleanValueNode.Value && isIncludedDirective)
{
selectionIsSkipped = false;
return true;
}
}
else
{
selectionIsSkipped = false;
}
}
}
}

return selectionIsSkipped;
return false;
}

private string GetNextRequirementName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void BindOperationVariables(
OperationDefinitionNode operationDefinition,
RequestPlanNode operationPlan)
{
var operationBacklog = new Stack<OperationPlanNode>(operationPlan.Operations.OfType<OperationPlanNode>());
var operationBacklog = new Stack<OperationPlanNode>(operationPlan.Operations);
var selectionBacklog = new Stack<SelectionPlanNode>();
var variableDefinitions = operationDefinition.VariableDefinitions.ToDictionary(t => t.Variable.Name.Value);
var usedVariables = new HashSet<string>();
Expand All @@ -18,7 +18,7 @@ public static void BindOperationVariables(
{
CollectAndBindUsedVariables(operation, variableDefinitions, usedVariables, selectionBacklog);

foreach (var child in operation.Dependants.OfType<OperationPlanNode>())
foreach (var child in operation.Dependants)
{
operationBacklog.Push(child);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Buffers;
using System.Buffers.Text;
using System.Text;
using System.Text.Json;
using HotChocolate.Fusion.Planning.Nodes;
Expand Down Expand Up @@ -77,7 +78,7 @@ private static void WriteOperationNode(

if (operation.IncludeVariable is not null)
{
writer.WriteLine(" includeIf: \"{0}\"", operation.SkipVariable);
writer.WriteLine(" includeIf: \"{0}\"", operation.IncludeVariable);
}

if (operation.Requirements.Count > 0)
Expand Down
Loading
Loading