Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Dec 9, 2024
1 parent 382e7f3 commit 3121252
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public string? SkipVariable
}
set
{
_includeVariable = value;
_skipVariable = value;
_isConditional = _skipVariable is not null || _includeVariable is not null;
}
}
Expand Down Expand Up @@ -147,6 +147,9 @@ public void AddDirective(CompositeDirective directive)
(_directives ??= []).Add(directive);
}

public bool RemoveDirective(CompositeDirective directive)
=> _directives?.Remove(directive) == true;

private void InitializeConditions()
{
if(_isConditional.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ private bool TryPlanFieldSelection(
// if we have an operation plan node we have a pre-validated set of
// root fields, so we now the field will be resolvable on the
// source schema.
if (context.Parent is OperationPlanNode || IsResolvable(fieldNode, field, context.Operation.SchemaName))
if (context.Parent is OperationPlanNode
|| IsResolvable(fieldNode, field, context.Operation.SchemaName))
{
var fieldNamedType = field.Type.NamedType();

Expand All @@ -150,7 +151,7 @@ private bool TryPlanFieldSelection(
}

var leafField = new FieldPlanNode(fieldNode, field);
PlanSelectionDirectives(leafField, fieldNode.Directives);
AddSelectionDirectives(leafField, fieldNode.Directives);
context.Parent.AddSelection(leafField);
return true;
}
Expand All @@ -167,7 +168,7 @@ private bool TryPlanFieldSelection(
}

var fieldPlanNode = new FieldPlanNode(fieldNode, field);
PlanSelectionDirectives(fieldPlanNode, fieldNode.Directives);
AddSelectionDirectives(fieldPlanNode, fieldNode.Directives);

var pathSegment = new SelectionPathSegment(fieldPlanNode);

Expand All @@ -186,13 +187,20 @@ private bool TryPlanFieldSelection(
return false;
}

private void PlanSelectionDirectives(
private void AddSelectionDirectives(
SelectionPlanNode selection,
IReadOnlyList<DirectiveNode> directiveNodes)
{
foreach (var directiveNode in directiveNodes)
{
var directiveType = schema.GetDirectiveType(directiveNode.Name.Value);

if ((directiveType == schema.SkipDirective || directiveType == schema.IncludeDirective)
&& directiveNode.Arguments[0].Value is BooleanValueNode)
{
continue;
}

var argumentAssignments = directiveNode.Arguments.Select(
a => new ArgumentAssignment(a.Name.Value, a.Value)).ToList();
selection.AddDirective(new CompositeDirective(directiveType, argumentAssignments));
Expand Down Expand Up @@ -603,7 +611,7 @@ private static FieldNode CreateFieldNodeFromPath(FieldPath path)
return current!;
}

private static void PlanConditionNode(
private void PlanConditionNode(
OperationPlanNode operation,
IReadOnlyList<SelectionPlanNode> selections)
{
Expand Down Expand Up @@ -632,10 +640,22 @@ private static void PlanConditionNode(
operation.SkipVariable = firstSelection.SkipVariable;
operation.IncludeVariable = firstSelection.IncludeVariable;

var remove = new List<CompositeDirective>();

foreach (var selection in selections)
{
selection.SkipVariable = null;
selection.IncludeVariable = null;

remove.AddRange(
selection.Directives.Where(
t => t.Type == schema.SkipDirective
|| t.Type == schema.IncludeDirective));

foreach (var directive in remove)
{
selection.RemoveDirective(directive);
}
}
}

Expand Down
Loading

0 comments on commit 3121252

Please sign in to comment.