Skip to content

Commit

Permalink
Make TryHandleUnresolvedSelections work
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Dec 12, 2024
1 parent e925468 commit e2e7031
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 114 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
@@ -1,4 +1,3 @@
using System.Collections;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using HotChocolate.Fusion.Planning.Nodes;
Expand Down Expand Up @@ -154,7 +153,6 @@ private bool TryPlanInlineFragmentSelection(
{
if (IsSelectionAlwaysSkipped(selection))
{
// TODO: How to reconcile this?
continue;
}

Expand Down Expand Up @@ -437,7 +435,14 @@ private bool TryHandleUnresolvedSelections(
break;

case InlineFragmentPlanNode inlineFragmentNode:
// TODO: Do we have to do this?
foreach (var inlineFragmentSelection in inlineFragmentNode.Selections)
{
if (inlineFragmentSelection is FieldPlanNode field)
{
processedFields.Add(field.Field.Name);
}
}

break;

default:
Expand All @@ -446,13 +451,26 @@ private bool TryHandleUnresolvedSelections(
}
}

// TODO: Uuuuuuuuuuuuuuugly hack, just to make tests work for now
if (unresolvedSelections.OfType<UnresolvedInlineFragment>().Any())
var unresolvedFields = new HashSet<string>();
foreach (var unresolvedSelection in unresolvedSelections)
{
return true;
if (unresolvedSelection is UnresolvedField unresolvedField)
{
unresolvedFields.Add(unresolvedField.Field.Name);
}
else if (unresolvedSelection is UnresolvedInlineFragment unresolvedInlineFragment)
{
foreach (var inlineFragmentSelection in unresolvedInlineFragment.UnresolvedSelections)
{
if (inlineFragmentSelection is UnresolvedField field)
{
unresolvedFields.Add(field.Field.Name);
}
}
}
}

return unresolvedSelections.Count == processedFields.Count;
return unresolvedFields.Count == processedFields.Count;
}

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

[Test]
[Skip("Doesn't work yet")]
public void Test()
{
// arrange
var compositeSchema = CreateCompositeSchema();

var request = Parse(
"""
query($id: ID!) {
reviewById(id: $id) {
body
author {
displayName
}
...ReviewFragment
}
}
fragment ReviewFragment on Review {
author {
id
displayName
reviews {
pageInfo {
hasNextPage
}
}
}
}
""");

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

// assert
plan.MatchSnapshot();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,34 @@ request:
}
}
nodes:
- id: 1
schema: "PRODUCTS"
operation: >-
query($slug: String!) {
productBySlug(slug: $slug) {
id
}
}
- id: 2
schema: "REVIEWS"
operation: >-
query($__fusion_requirement_1: ID!) {
productById(id: $__fusion_requirement_1) {
reviews {
nodes {
body
}
}
reviews {
pageInfo {
hasNextPage
}
}
}
}
requirements:
- name: "__fusion_requirement_1"
dependsOn: "1"
selectionSet: "productBySlug"
field: "id"
type: "ID!"

0 comments on commit e2e7031

Please sign in to comment.