Skip to content

Commit 2faaad3

Browse files
authored
chore: fix comments and formatting in debug (#1356)
Something I fixed as I read the code.
1 parent 16905bc commit 2faaad3

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

v2/pkg/engine/plan/datasource_filter_visitor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func (f *DataSourceFilter) applyLandedTo(landedTo map[int]DSHash) {
142142

143143
}
144144

145+
// collectNodes collects and organizes information about
146+
// which data sources (subgraphs) can resolve each field and
147+
// builds a "jump graph" to enable navigation between data sources using federation @key directives.
145148
func (f *DataSourceFilter) collectNodes() {
146149
if f.nodesCollector == nil {
147150
f.nodesCollector = &nodesCollector{

v2/pkg/engine/plan/node_selection_builder.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document,
110110
}
111111

112112
if p.config.Debug.PrintNodeSuggestions {
113-
p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nInitial node suggestions:\n", p.config.Debug.PrintNodeSuggestionsFilterNotSelected)
113+
p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nInitial node suggestions:\n",
114+
p.config.Debug.PrintNodeSuggestionsFilterNotSelected)
114115
}
115116

116117
p.nodeSelectionsVisitor.secondaryRun = false
@@ -126,10 +127,10 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document,
126127

127128
i := 1
128129
hasUnresolvedFields := false
129-
// secondary runs to add path for the new required fields
130+
// Additional runs to add paths for the new required fields
130131
for p.nodeSelectionsVisitor.hasNewFields || hasUnresolvedFields {
131-
// when we have rewritten a field old node suggestion are not make sense anymore
132-
// so we are removing child nodes of the rewritten fields
132+
// When we have rewritten a field, the old node suggestion does not make sense anymore:
133+
// we have to remove child nodes of the rewritten fields.
133134
for _, fieldRef := range p.nodeSelectionsVisitor.rewrittenFieldRefs {
134135
p.nodeSelectionsVisitor.nodeSuggestions.RemoveTreeNodeChilds(fieldRef)
135136
}

v2/pkg/engine/plan/node_selection_visitor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
)
1111

1212
// nodeSelectionVisitor walks through the operation multiple times to rewrite it
13-
// to be able to resolve fields from different datasources.
14-
// This visitor might add required fields and rewrite abstract selection if necessary.
13+
// to be able to resolve fields from different data sources.
14+
// If necessary, this visitor might add required fields and rewrite abstract selections.
1515
//
1616
// This visitor will walk the operation again if it has:
1717
// - added new required fields to the operation,
@@ -220,7 +220,7 @@ func (c *nodeSelectionVisitor) handleEnterField(fieldRef int, handleRequires boo
220220
fieldAliasOrName := c.operation.FieldAliasOrNameString(fieldRef)
221221
typeName := c.walker.EnclosingTypeDefinition.NameString(c.definition)
222222

223-
c.debugPrint("EnterField ref:", fieldRef, "fieldName:", fieldName, "typeName:", typeName)
223+
c.debugPrint("EnterField ref:", fieldRef, "fieldName:", fieldName, "typeName:", typeName, "requires:", handleRequires)
224224

225225
parentPath := c.walker.Path.DotDelimitedString()
226226
currentPath := parentPath + "." + fieldAliasOrName

v2/pkg/engine/plan/planner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (p *Planner) Plan(operation, definition *ast.Document, operationName string
144144
}
145145

146146
if p.config.Debug.PlanningVisitor {
147-
debugMessage("Planning visitor:")
147+
debugMessage("Planning Visitor\n================")
148148
}
149149

150150
// configure planning visitor

v2/pkg/engine/plan/visitor.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func (v *Visitor) debugOnEnterNode(kind ast.NodeKind, ref int) {
8080
case ast.NodeKindField:
8181
fieldName := v.Operation.FieldNameString(ref)
8282
fullPath := v.currentFullPath(false)
83-
v.debugPrint("EnterField : ", fieldName, " ref: ", ref, " path: ", fullPath)
83+
v.debugPrint("EnterField:", fieldName, " ref:", ref, " path:", fullPath)
8484
case ast.NodeKindInlineFragment:
8585
fragmentTypeCondition := v.Operation.InlineFragmentTypeConditionNameString(ref)
86-
v.debugPrint("EnterInlineFragment : ", fragmentTypeCondition, " ref: ", ref)
86+
v.debugPrint("EnterInlineFragment:", fragmentTypeCondition, " ref:", ref)
8787
case ast.NodeKindSelectionSet:
88-
v.debugPrint("EnterSelectionSet", " ref: ", ref)
88+
v.debugPrint("EnterSelectionSet", " ref:", ref)
8989
}
9090
}
9191

@@ -98,12 +98,12 @@ func (v *Visitor) debugOnLeaveNode(kind ast.NodeKind, ref int) {
9898
case ast.NodeKindField:
9999
fieldName := v.Operation.FieldNameString(ref)
100100
fullPath := v.currentFullPath(false)
101-
v.debugPrint("LeaveField : ", fieldName, " ref: ", ref, " path: ", fullPath)
101+
v.debugPrint("LeaveField:", fieldName, " ref:", ref, " path:", fullPath)
102102
case ast.NodeKindInlineFragment:
103103
fragmentTypeCondition := v.Operation.InlineFragmentTypeConditionNameString(ref)
104-
v.debugPrint("LeaveInlineFragment : ", fragmentTypeCondition, " ref: ", ref)
104+
v.debugPrint("LeaveInlineFragment:", fragmentTypeCondition, " ref:", ref)
105105
case ast.NodeKindSelectionSet:
106-
v.debugPrint("LeaveSelectionSet", " ref: ", ref)
106+
v.debugPrint("LeaveSelectionSet", " ref:", ref)
107107
}
108108
}
109109

0 commit comments

Comments
 (0)