Skip to content

Commit 16905bc

Browse files
authored
chore: improve debug formatting in path builder (#1355)
This produces format that is easier to read: ``` CreatePlanningPaths =================== [pathBuilderVisitor]: EnterSelectionSet ref: 2 [pathBuilderVisitor]: EnterField ref: 2 fieldName: accounts typeName: Query [pathBuilderVisitor]: saveAddedPath {"ds":11987355753863978781,"path":"query","shouldWalkFields":true,"pathType":"parent"} [pathBuilderVisitor]: saveAddedPath {"ds":11987355753863978781,"path":"query.accounts","fieldRef": 2,"typeName":"Query","shouldWalkFields":true,"isRootNode":true,"pathType":"field"} ... SNIP ... [pathBuilderVisitor]: LeaveSelectionSet ref: 2 Planned paths on initial run #1: should revisit has missing paths has fields waiting for dependency Missing paths: query.accounts.full Run #1. Planner ID 0 ParentPath: query Datasource ID: id-1, name: id-1, hash: 11987355753863978781 Paths: {"ds":11987355753863978781,"path":"query","shouldWalkFields":true,"pathType":"parent"} {"ds":11987355753863978781,"path":"query.accounts","fieldRef": 2,"typeName":"Query","shouldWalkFields":true,"isRootNode":true,"pathType":"field"} {"ds":11987355753863978781,"path":"query.accounts.id","fieldRef": 0,"typeName":"User","shouldWalkFields":true,"isRootNode":true,"pathType":"field"} {"ds":11987355753863978781,"path":"query.accounts.__typename","fieldRef": 4,"typeName":"User","shouldWalkFields":true,"isRootNode":false,"pathType":"field"} Run #1. Planner ID 1 ParentPath: query.accounts Datasource ID: id-2, name: id-2, hash: 14787246084284009732 Depends on planner IDs: [0] Required fields: key: {"type_name":"User","selection_set":"id","RemappedPaths":null} Paths: {"ds":14787246084284009732,"path":"query.accounts","shouldWalkFields":true,"pathType":"parent"} {"ds":14787246084284009732,"path":"query.accounts.title","fieldRef": 3,"typeName":"User","shouldWalkFields":true,"isRootNode":true,"pathType":"field"} [pathBuilderVisitor]: EnterSelectionSet ref: 2 [pathBuilderVisitor]: EnterField ref: 2 fieldName: accounts typeName: Query [pathBuilderVisitor]: EnterSelectionSet ref: 1 ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Standardized and clarified diagnostic/log output across selection and planning flows: run-aware headers, consistent labeling/indentation, unified messages for node selection and path planning, improved revisit/missing-path reporting, and deterministic handling of potentially missing paths to improve troubleshooting. * **Tests** * Non-functional test change: an optional debug line added but left commented out (no behavior change). <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8200315 commit 16905bc

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

execution/engine/execution_engine_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func TestExecutionEngine_Execute(t *testing.T) {
263263
engineConf.plannerConfig.Debug = plan.DebugConfiguration{
264264
// PrintOperationTransformations: true,
265265
// PrintPlanningPaths: true,
266+
// PrintNodeSuggestions: true,
266267
// PrintQueryPlans: true,
267268
// ConfigurationVisitor: true,
268269
// PlanningVisitor: true,

v2/pkg/engine/plan/node_selection_builder.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document,
9696
}
9797

9898
if p.config.Debug.PrintOperationTransformations {
99-
debugMessage("Initial operation:")
99+
debugMessage("SelectNodes. Initial operation:\n===========")
100100
p.printOperation(operation)
101101
}
102102

@@ -120,7 +120,7 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document,
120120
}
121121

122122
if p.config.Debug.PrintOperationTransformations {
123-
debugMessage("Select nodes initial run - operation:")
123+
debugMessage("Selected nodes on run #1 for operation:")
124124
p.printOperation(operation)
125125
}
126126

@@ -146,11 +146,11 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document,
146146
}
147147

148148
if p.config.Debug.PrintOperationTransformations || p.config.Debug.PrintNodeSuggestions {
149-
debugMessage(fmt.Sprintf("Select nodes run #%d", i))
149+
debugMessage(fmt.Sprintf("Selected nodes on additional run #%d.", i+1))
150150
}
151151

152152
if p.config.Debug.PrintNodeSuggestions {
153-
p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nRecalculated node suggestions:\n", p.config.Debug.PrintNodeSuggestionsFilterNotSelected)
153+
p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nUpdated node suggestions:\n", p.config.Debug.PrintNodeSuggestionsFilterNotSelected)
154154
}
155155

156156
p.nodeSelectionsWalker.Walk(operation, definition, report)
@@ -159,8 +159,7 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document,
159159
}
160160

161161
if p.config.Debug.PrintOperationTransformations {
162-
debugMessage("Operation with new required fields:")
163-
debugMessage(fmt.Sprintf("Has new fields: %v", p.nodeSelectionsVisitor.hasNewFields))
162+
debugMessage(fmt.Sprintf("Operation with new required fields (has new fields: %v):", p.nodeSelectionsVisitor.hasNewFields))
164163
p.printOperation(operation)
165164
}
166165

v2/pkg/engine/plan/path_builder.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (p *PathBuilder) SetOperationName(name string) {
4545

4646
func (p *PathBuilder) CreatePlanningPaths(operation, definition *ast.Document, report *operationreport.Report) []PlannerConfiguration {
4747
if p.config.Debug.PrintPlanningPaths {
48-
debugMessage("Create planning paths")
48+
debugMessage("CreatePlanningPaths\n===================")
4949
}
5050

5151
p.visitor.plannerConfiguration = p.config
@@ -71,9 +71,9 @@ func (p *PathBuilder) CreatePlanningPaths(operation, definition *ast.Document, r
7171
// - walker.Stop was called and visiting was halted
7272

7373
if p.config.Debug.PrintPlanningPaths {
74-
debugMessage("Planning paths after initial run")
74+
fmt.Printf("\nPlanned paths on initial run #1:\n")
7575
p.printRevisitInfo()
76-
p.printPlanningPaths()
76+
p.printPlanningPaths(1)
7777
}
7878

7979
i := 1
@@ -89,12 +89,9 @@ func (p *PathBuilder) CreatePlanningPaths(operation, definition *ast.Document, r
8989
p.visitor.populateMissingPaths()
9090

9191
if p.config.Debug.PrintPlanningPaths {
92-
debugMessage(fmt.Sprintf("Create planning paths run #%d", i))
93-
}
94-
95-
if p.config.Debug.PrintPlanningPaths {
92+
fmt.Printf("\nPlanned paths on run #%d:\n", i+1)
9693
p.printRevisitInfo()
97-
p.printPlanningPaths()
94+
p.printPlanningPaths(i + 1)
9895
}
9996

10097
i++
@@ -116,8 +113,8 @@ func (p *PathBuilder) CreatePlanningPaths(operation, definition *ast.Document, r
116113
// remove unnecessary fragment paths
117114
hasRemovedPaths := p.removeUnnecessaryFragmentPaths()
118115
if hasRemovedPaths && p.config.Debug.PrintPlanningPaths {
119-
debugMessage("After removing unnecessary fragment paths")
120-
p.printPlanningPaths()
116+
debugMessage("Final paths after removing unnecessary fragment paths:")
117+
p.printPlanningPaths(i)
121118
}
122119

123120
return p.visitor.planners
@@ -138,34 +135,41 @@ func (p *PathBuilder) removeUnnecessaryFragmentPaths() (hasRemovedPaths bool) {
138135
}
139136

140137
func (p *PathBuilder) printRevisitInfo() {
141-
fmt.Println("Should revisit:", p.visitor.shouldRevisit())
142-
fmt.Println("Has missing paths:", p.visitor.hasMissingPaths())
143-
fmt.Println("Has fields waiting for dependency:", p.visitor.hasFieldsWaitingForDependency())
138+
if p.visitor.shouldRevisit() {
139+
fmt.Println(" should revisit")
140+
}
141+
if p.visitor.hasMissingPaths() {
142+
fmt.Println(" has missing paths")
143+
}
144+
if p.visitor.hasFieldsWaitingForDependency() {
145+
fmt.Println(" has fields waiting for dependency")
146+
}
144147

145148
p.printMissingPaths()
146149
}
147150

148-
func (p *PathBuilder) printPlanningPaths() {
149-
debugMessage("\n\nPlanning paths:\n\n")
151+
func (p *PathBuilder) printPlanningPaths(run int) {
150152
for i, planner := range p.visitor.planners {
151-
fmt.Printf("\nPlanner id: %d\n", i)
152-
fmt.Printf("Parent path: %s\n", planner.ParentPath())
153+
fmt.Printf("\nRun #%d. Planner ID %d\n", run, i)
154+
fmt.Printf(" ParentPath: %s\n", planner.ParentPath())
153155
ds := planner.DataSourceConfiguration()
154-
fmt.Printf("Datasource id: %s name: %s hash: %d\n", ds.Id(), ds.Name(), ds.Hash())
155-
fmt.Printf("Depends on planner ids: %v\n", planner.ObjectFetchConfiguration().dependsOnFetchIDs)
156+
fmt.Printf(" Datasource ID: %s, name: %s, hash: %d\n", ds.Id(), ds.Name(), ds.Hash())
157+
if len(planner.ObjectFetchConfiguration().dependsOnFetchIDs) > 0 {
158+
fmt.Printf(" Depends on planner IDs: %v\n", planner.ObjectFetchConfiguration().dependsOnFetchIDs)
159+
}
156160

157161
requiredFields := planner.RequiredFields()
158162
if requiredFields != nil && len(*requiredFields) > 0 {
159-
fmt.Println("Required fields:")
163+
fmt.Println(" Required fields:")
160164
for _, field := range *requiredFields {
161165
if field.FieldName != "" {
162-
fmt.Printf("required by %s: %s\n", field.FieldName, field)
166+
fmt.Printf(" required by %s: %s\n", field.FieldName, field)
163167
continue
164168
}
165-
fmt.Println("key:", field)
169+
fmt.Println(" key:", field)
166170
}
167171
}
168-
fmt.Println("Paths:")
172+
fmt.Println(" Paths:")
169173
planner.ForEachPath(func(path *pathConfiguration) (shouldBreak bool) {
170174
fmt.Println(path.String())
171175
return false
@@ -176,9 +180,9 @@ func (p *PathBuilder) printPlanningPaths() {
176180

177181
func (p *PathBuilder) printMissingPaths() {
178182
if p.visitor.hasMissingPaths() {
179-
debugMessage("Missing paths:")
183+
fmt.Printf("\n Missing paths:\n")
180184
for path := range p.visitor.missingPathTracker {
181-
fmt.Println(path)
185+
fmt.Printf(" %v\n", path)
182186
}
183187
}
184188
}

v2/pkg/engine/plan/path_builder_visitor.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,13 +1232,12 @@ func (c *pathBuilderVisitor) handleMissingPath(planned bool, typeName string, fi
12321232
if planned {
12331233
// __typename field on a union could not have a suggestion
12341234
return
1235-
} else {
1236-
if c.plannerConfiguration.Debug.PrintPlanningPaths {
1237-
fmt.Println("Adding potentially missing path", currentPath)
1238-
}
1235+
}
12391236

1240-
c.potentiallyMissingPathTracker[currentPath] = struct{}{}
1237+
if c.plannerConfiguration.Debug.PrintPlanningPaths {
1238+
fmt.Println("Found potentially missing path", currentPath)
12411239
}
1240+
c.potentiallyMissingPathTracker[currentPath] = struct{}{}
12421241
}
12431242

12441243
allSuggestionsPlanned := true

0 commit comments

Comments
 (0)