Skip to content

Commit

Permalink
[Fusion vNext] Add support for @skip / @include on fragments (#7808)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler authored Dec 13, 2024
1 parent 9021541 commit f3e7ff2
Show file tree
Hide file tree
Showing 37 changed files with 2,169 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace HotChocolate.Fusion.Planning;

// TODO: We need to merge selections
public sealed class InlineFragmentOperationRewriter(CompositeSchema schema)
{
public DocumentNode RewriteDocument(DocumentNode document, string? operationName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ public sealed class InlineFragmentPlanNode : SelectionPlanNode
public InlineFragmentPlanNode(
ICompositeNamedType declaringType,
InlineFragmentNode inlineFragment)
: this(declaringType, inlineFragment.SelectionSet.Selections)
: this(declaringType, inlineFragment.Directives, inlineFragment.SelectionSet.Selections)
{
}

public InlineFragmentPlanNode(
ICompositeNamedType declaringType,
IReadOnlyList<DirectiveNode> directiveNodes,
IReadOnlyList<ISelectionNode> selectionNodes)
: base(declaringType, [], selectionNodes)
: base(declaringType, directiveNodes, selectionNodes)
{
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ private static void CollectAndBindUsedVariables(
usedVariables.Add(variable.Name.Value);
}
}
}

foreach (var directive in field.Directives)
foreach (var directive in node.Directives)
{
foreach (var argument in directive.Arguments)
{
foreach (var argument in directive.Arguments)
if (argument.Value is VariableNode variable)
{
if (argument.Value is VariableNode variable)
{
usedVariables.Add(variable.Name.Value);
}
usedVariables.Add(variable.Name.Value);
}
}
}
Expand All @@ -67,7 +67,7 @@ private static void CollectAndBindUsedVariables(

foreach (var variable in usedVariables)
{
if(variableDefinitions.TryGetValue(variable, out var variableDefinition))
if (variableDefinitions.TryGetValue(variable, out var variableDefinition))
{
operation.AddVariableDefinition(variableDefinition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace HotChocolate.Fusion;

// TODO: Test shared skip selection with one selection having an include - should fail today incorrectly!
public class SkipAndIncludeTests : FusionTestBase
{
[Test]
Expand Down
Loading

0 comments on commit f3e7ff2

Please sign in to comment.