diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/OperationPlanner.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/OperationPlanner.cs index 48faf115807..ebcd5dda618 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/OperationPlanner.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/OperationPlanner.cs @@ -286,12 +286,6 @@ private bool TryHandleUnresolvedSelections( schemasInContext[requiredSchema].AddDependantOperation(lookupOperation); } - // TODO: we need to include the entity path in here. - // actually ... we need to redo the whole path thingy. - // only the first one is path - entity path. - // second one is operation + entity path. - var currentSelectionPath = CreateFieldPath(context.Path); - // add requirements to the operation for (var i = 0; i < lookup.Fields.Length; i++) { @@ -299,17 +293,19 @@ private bool TryHandleUnresolvedSelections( var requiredField = lookup.Fields[i]; var argument = lookup.Arguments[i]; - // should we store on the requirement the operation from which data is required? var requiredFromSchema = fieldSchemaDependencies[requiredField]; var requiredFromOperation = schemasInContext[requiredFromSchema]; var requiredFromSelectionSet = requiredFromOperation != context.Operation ? requiredFromOperation.Selections.Single() : context.Parent; + var requiredFromPathStack = requiredFromOperation != context.Operation + ? ImmutableStack.Empty.Push(new SelectionPathSegment(lookupField)) + : context.Path; + var requiredFromPath = CreateFieldPath(requiredFromPathStack); var requiredFromContext = new PlaningContext( requiredFromOperation, requiredFromSelectionSet, - // path is wrong ... we must check if this is a lookup context and build new path for it - context.Path); + requiredFromPathStack); if (!TryPlanSelection( requiredFromContext, @@ -323,7 +319,7 @@ private bool TryHandleUnresolvedSelections( var requirement = new FieldRequirementPlanNode( requirementName, requiredFromOperation, - currentSelectionPath, + requiredFromPath, requiredField, argument.Type); @@ -582,7 +578,7 @@ private static FieldPath CreateFieldPath(ImmutableStack pa { var current = FieldPath.Root; - foreach (var segment in path) + foreach (var segment in path.Reverse()) { if (segment.PlanNode is FieldPlanNode field) { diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeJsonFormatter.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeJsonFormatter.cs index 7ae9a24d687..33e1c110675 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeJsonFormatter.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeJsonFormatter.cs @@ -66,7 +66,7 @@ private static void WriteOperationNode( writer.WriteString("name", requirement.Name); writer.WriteNumber("dependsOn", nodeIdLookup[requirement.From]); - writer.WritePropertyName("field"); + writer.WritePropertyName("selectionSet"); writer.WriteStartArray(); foreach (var segment in requirement.SelectionSet.Reverse()) @@ -76,6 +76,16 @@ private static void WriteOperationNode( writer.WriteEndArray(); + writer.WritePropertyName("field"); + writer.WriteStartArray(); + + foreach (var segment in requirement.RequiredField.Reverse()) + { + writer.WriteStringValue(segment.Name); + } + + writer.WriteEndArray(); + writer.WriteString("type", requirement.Type.ToString(false)); writer.WriteEndObject(); } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeYamlFormatter.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeYamlFormatter.cs index 159b0d105c0..282a08e0349 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeYamlFormatter.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/PlanNodeYamlFormatter.cs @@ -68,7 +68,8 @@ private static void WriteOperationNode( { writer.WriteLine(" - name: \"{0}\"", requirement.Name); writer.WriteLine(" dependsOn: \"{0}\"", nodeIdLookup[requirement.From]); - writer.WriteLine(" field: \"{0}\"", requirement.SelectionSet); + writer.WriteLine(" selectionSet: \"{0}\"", requirement.SelectionSet); + writer.WriteLine(" field: \"{0}\"", requirement.RequiredField); writer.WriteLine(" type: \"{0}\"", requirement.Type.ToString(false)); } } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Types/FieldPath.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Types/FieldPath.cs index 4702162e8c9..819d808a17a 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Types/FieldPath.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Types/FieldPath.cs @@ -137,12 +137,21 @@ public override string ToString() do { + if(ReferenceEquals(current, Root)) + { + break; + } + if (first) { - path.Insert(0, current.Name); - path.Insert(0, '.'); first = false; } + else + { + path.Insert(0, "."); + } + + path.Insert(0, current.Name); current = current.Parent; } while (current != null); diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ConditionTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ConditionTests.cs index 24607c199d1..70579d76eb0 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ConditionTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/ConditionTests.cs @@ -259,7 +259,8 @@ query GetProduct($id: ID!, $skip: Boolean!) { requirements: - name: "__fusion_requirement_1" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" """); @@ -317,7 +318,8 @@ query GetProduct($id: ID!) { requirements: - name: "__fusion_requirement_1" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" """); @@ -370,7 +372,8 @@ query GetProduct($id: ID!) { requirements: - name: "__fusion_requirement_1" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" """); @@ -427,7 +430,8 @@ query GetProduct($id: ID!, $skip: Boolean!) { requirements: - name: "__fusion_requirement_1" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" """); @@ -483,7 +487,8 @@ query GetProduct($id: ID!) { requirements: - name: "__fusion_requirement_1" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" """); diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs index 520d1811ca3..b4c1e9fc0aa 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/OperationPlannerTests.cs @@ -1,5 +1,4 @@ using HotChocolate.Fusion.Planning; -using HotChocolate.Fusion.Planning.Nodes; using HotChocolate.Fusion.Types.Completion; using HotChocolate.Language; @@ -94,7 +93,8 @@ fragment Product on Product { requirements: - name: "__fusion_requirement_1" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" """); @@ -170,7 +170,8 @@ fragment AuthorCard on UserProfile { requirements: - name: "__fusion_requirement_2" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" - id: 3 schema: "ACCOUNTS" @@ -183,7 +184,8 @@ fragment AuthorCard on UserProfile { requirements: - name: "__fusion_requirement_1" dependsOn: "2" - field: ".productById" + selectionSet: "productById.reviews.nodes.author" + field: "id" type: "ID!" """); @@ -259,7 +261,8 @@ fragment AuthorCard on UserProfile { requirements: - name: "__fusion_requirement_2" dependsOn: "1" - field: ".productById" + selectionSet: "productById" + field: "id" type: "ID!" - id: 3 schema: "ACCOUNTS" @@ -272,7 +275,8 @@ fragment AuthorCard on UserProfile { requirements: - name: "__fusion_requirement_1" dependsOn: "2" - field: ".productById" + selectionSet: "productById.reviews.nodes.author" + field: "id" type: "ID!" """);