Skip to content

Commit

Permalink
Add test for fields from different subgraphs in skipped fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Dec 11, 2024
1 parent c7cbf76 commit f241a64
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ private bool TryPlanInlineFragmentSelection(
});
}

if (unresolvedSelections is { Count: > 0 })
{
var unresolvedInlineFragment =
new UnresolvedInlineFragment(inlineFragmentNode.Directives, typeCondition, unresolvedSelections);

trackUnresolvedSelection(unresolvedInlineFragment);
}

if (inlineFragmentPlanNode.Selections.Count > 0)
{
AddSelectionDirectives(inlineFragmentPlanNode, inlineFragmentNode.Directives);
Expand All @@ -178,14 +186,6 @@ private bool TryPlanInlineFragmentSelection(
return true;
}

if (unresolvedSelections is { Count: > 0 })
{
var unresolvedInlineFragment =
new UnresolvedInlineFragment(inlineFragmentNode.Directives, typeCondition, unresolvedSelections);

trackUnresolvedSelection(unresolvedInlineFragment);
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,33 @@ fragment ProductFragment2 on Product {
// assert
plan.MatchSnapshot();
}



[Test]
public void Skipped_Sub_Fragment_With_Fields_From_Different_Subgraphs()
{
// arrange
var compositeSchema = CreateCompositeSchema();

var request = Parse(
"""
query($slug: String!, $skip: Boolean!) {
productBySlug(slug: $slug) {
... ProductFragment @skip(if: $skip)
}
}
fragment ProductFragment on Product {
name
averageRating
}
""");

// act
var plan = PlanOperation(request, compositeSchema);

// assert
plan.MatchSnapshot();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
request:
- document: >-
query($slug: String!, $skip: Boolean!) {
productBySlug(slug: $slug) {
... on Product @skip(if: $skip) {
name
averageRating
}
}
}
nodes:
- id: 1
schema: "PRODUCTS"
operation: >-
query($skip: Boolean!, $slug: String!) {
productBySlug(slug: $slug) {
... on Product @skip(if: $skip) {
name
}
id
}
}
- id: 2
schema: "REVIEWS"
operation: >-
query($__fusion_requirement_1: ID!) {
productById(id: $__fusion_requirement_1) {
... on Product {
averageRating
}
}
}
skipIf: "skip"
requirements:
- name: "__fusion_requirement_1"
dependsOn: "1"
selectionSet: "productBySlug"
field: "id"
type: "ID!"

0 comments on commit f241a64

Please sign in to comment.