diff --git a/v2/pkg/engine/plan/datasource_filter_visitor.go b/v2/pkg/engine/plan/datasource_filter_visitor.go index 940d86cd02..c67614cc0a 100644 --- a/v2/pkg/engine/plan/datasource_filter_visitor.go +++ b/v2/pkg/engine/plan/datasource_filter_visitor.go @@ -142,6 +142,9 @@ func (f *DataSourceFilter) applyLandedTo(landedTo map[int]DSHash) { } +// collectNodes collects and organizes information about +// which data sources (subgraphs) can resolve each field and +// builds a "jump graph" to enable navigation between data sources using federation @key directives. func (f *DataSourceFilter) collectNodes() { if f.nodesCollector == nil { f.nodesCollector = &nodesCollector{ diff --git a/v2/pkg/engine/plan/node_selection_builder.go b/v2/pkg/engine/plan/node_selection_builder.go index 36a210bc25..b60363c289 100644 --- a/v2/pkg/engine/plan/node_selection_builder.go +++ b/v2/pkg/engine/plan/node_selection_builder.go @@ -110,7 +110,8 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document, } if p.config.Debug.PrintNodeSuggestions { - p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nInitial node suggestions:\n", p.config.Debug.PrintNodeSuggestionsFilterNotSelected) + p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nInitial node suggestions:\n", + p.config.Debug.PrintNodeSuggestionsFilterNotSelected) } p.nodeSelectionsVisitor.secondaryRun = false @@ -126,10 +127,10 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document, i := 1 hasUnresolvedFields := false - // secondary runs to add path for the new required fields + // Additional runs to add paths for the new required fields for p.nodeSelectionsVisitor.hasNewFields || hasUnresolvedFields { - // when we have rewritten a field old node suggestion are not make sense anymore - // so we are removing child nodes of the rewritten fields + // When we have rewritten a field, the old node suggestion does not make sense anymore: + // we have to remove child nodes of the rewritten fields. for _, fieldRef := range p.nodeSelectionsVisitor.rewrittenFieldRefs { p.nodeSelectionsVisitor.nodeSuggestions.RemoveTreeNodeChilds(fieldRef) } diff --git a/v2/pkg/engine/plan/node_selection_visitor.go b/v2/pkg/engine/plan/node_selection_visitor.go index ee59305f4c..8f9f80fb48 100644 --- a/v2/pkg/engine/plan/node_selection_visitor.go +++ b/v2/pkg/engine/plan/node_selection_visitor.go @@ -10,8 +10,8 @@ import ( ) // nodeSelectionVisitor walks through the operation multiple times to rewrite it -// to be able to resolve fields from different datasources. -// This visitor might add required fields and rewrite abstract selection if necessary. +// to be able to resolve fields from different data sources. +// If necessary, this visitor might add required fields and rewrite abstract selections. // // This visitor will walk the operation again if it has: // - added new required fields to the operation, @@ -220,7 +220,7 @@ func (c *nodeSelectionVisitor) handleEnterField(fieldRef int, handleRequires boo fieldAliasOrName := c.operation.FieldAliasOrNameString(fieldRef) typeName := c.walker.EnclosingTypeDefinition.NameString(c.definition) - c.debugPrint("EnterField ref:", fieldRef, "fieldName:", fieldName, "typeName:", typeName) + c.debugPrint("EnterField ref:", fieldRef, "fieldName:", fieldName, "typeName:", typeName, "requires:", handleRequires) parentPath := c.walker.Path.DotDelimitedString() currentPath := parentPath + "." + fieldAliasOrName diff --git a/v2/pkg/engine/plan/planner.go b/v2/pkg/engine/plan/planner.go index 77f1de78ce..7b948ab6bd 100644 --- a/v2/pkg/engine/plan/planner.go +++ b/v2/pkg/engine/plan/planner.go @@ -144,7 +144,7 @@ func (p *Planner) Plan(operation, definition *ast.Document, operationName string } if p.config.Debug.PlanningVisitor { - debugMessage("Planning visitor:") + debugMessage("Planning Visitor\n================") } // configure planning visitor diff --git a/v2/pkg/engine/plan/visitor.go b/v2/pkg/engine/plan/visitor.go index ceafa757ec..1f8a469d05 100644 --- a/v2/pkg/engine/plan/visitor.go +++ b/v2/pkg/engine/plan/visitor.go @@ -80,12 +80,12 @@ func (v *Visitor) debugOnEnterNode(kind ast.NodeKind, ref int) { case ast.NodeKindField: fieldName := v.Operation.FieldNameString(ref) fullPath := v.currentFullPath(false) - v.debugPrint("EnterField : ", fieldName, " ref: ", ref, " path: ", fullPath) + v.debugPrint("EnterField:", fieldName, " ref:", ref, " path:", fullPath) case ast.NodeKindInlineFragment: fragmentTypeCondition := v.Operation.InlineFragmentTypeConditionNameString(ref) - v.debugPrint("EnterInlineFragment : ", fragmentTypeCondition, " ref: ", ref) + v.debugPrint("EnterInlineFragment:", fragmentTypeCondition, " ref:", ref) case ast.NodeKindSelectionSet: - v.debugPrint("EnterSelectionSet", " ref: ", ref) + v.debugPrint("EnterSelectionSet", " ref:", ref) } } @@ -98,12 +98,12 @@ func (v *Visitor) debugOnLeaveNode(kind ast.NodeKind, ref int) { case ast.NodeKindField: fieldName := v.Operation.FieldNameString(ref) fullPath := v.currentFullPath(false) - v.debugPrint("LeaveField : ", fieldName, " ref: ", ref, " path: ", fullPath) + v.debugPrint("LeaveField:", fieldName, " ref:", ref, " path:", fullPath) case ast.NodeKindInlineFragment: fragmentTypeCondition := v.Operation.InlineFragmentTypeConditionNameString(ref) - v.debugPrint("LeaveInlineFragment : ", fragmentTypeCondition, " ref: ", ref) + v.debugPrint("LeaveInlineFragment:", fragmentTypeCondition, " ref:", ref) case ast.NodeKindSelectionSet: - v.debugPrint("LeaveSelectionSet", " ref: ", ref) + v.debugPrint("LeaveSelectionSet", " ref:", ref) } }