Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions execution/engine/execution_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func TestExecutionEngine_Execute(t *testing.T) {
engineConf.plannerConfig.Debug = plan.DebugConfiguration{
// PrintOperationTransformations: true,
// PrintPlanningPaths: true,
// PrintNodeSuggestions: true,
// PrintQueryPlans: true,
// ConfigurationVisitor: true,
// PlanningVisitor: true,
Expand Down
11 changes: 5 additions & 6 deletions v2/pkg/engine/plan/node_selection_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *NodeSelectionBuilder) SelectNodes(operation, definition *ast.Document,
}

if p.config.Debug.PrintOperationTransformations {
debugMessage("Initial operation:")
debugMessage("SelectNodes. Initial operation:\n===========")
p.printOperation(operation)
}

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

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

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

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

if p.config.Debug.PrintNodeSuggestions {
p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nRecalculated node suggestions:\n", p.config.Debug.PrintNodeSuggestionsFilterNotSelected)
p.nodeSelectionsVisitor.nodeSuggestions.printNodesWithFilter("\nUpdated node suggestions:\n", p.config.Debug.PrintNodeSuggestionsFilterNotSelected)
}

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

if p.config.Debug.PrintOperationTransformations {
debugMessage("Operation with new required fields:")
debugMessage(fmt.Sprintf("Has new fields: %v", p.nodeSelectionsVisitor.hasNewFields))
debugMessage(fmt.Sprintf("Operation with new required fields (has new fields: %v):", p.nodeSelectionsVisitor.hasNewFields))
p.printOperation(operation)
}

Expand Down
54 changes: 29 additions & 25 deletions v2/pkg/engine/plan/path_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *PathBuilder) SetOperationName(name string) {

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

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

if p.config.Debug.PrintPlanningPaths {
debugMessage("Planning paths after initial run")
fmt.Printf("\nPlanned paths on initial run #1:\n")
p.printRevisitInfo()
p.printPlanningPaths()
p.printPlanningPaths(1)
}

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

if p.config.Debug.PrintPlanningPaths {
debugMessage(fmt.Sprintf("Create planning paths run #%d", i))
}

if p.config.Debug.PrintPlanningPaths {
fmt.Printf("\nPlanned paths on run #%d:\n", i+1)
p.printRevisitInfo()
p.printPlanningPaths()
p.printPlanningPaths(i + 1)
}

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

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

func (p *PathBuilder) printRevisitInfo() {
fmt.Println("Should revisit:", p.visitor.shouldRevisit())
fmt.Println("Has missing paths:", p.visitor.hasMissingPaths())
fmt.Println("Has fields waiting for dependency:", p.visitor.hasFieldsWaitingForDependency())
if p.visitor.shouldRevisit() {
fmt.Println(" should revisit")
}
if p.visitor.hasMissingPaths() {
fmt.Println(" has missing paths")
}
if p.visitor.hasFieldsWaitingForDependency() {
fmt.Println(" has fields waiting for dependency")
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

p.printMissingPaths()
}

func (p *PathBuilder) printPlanningPaths() {
debugMessage("\n\nPlanning paths:\n\n")
func (p *PathBuilder) printPlanningPaths(run int) {
for i, planner := range p.visitor.planners {
fmt.Printf("\nPlanner id: %d\n", i)
fmt.Printf("Parent path: %s\n", planner.ParentPath())
fmt.Printf("\nRun #%d. Planner ID %d\n", run, i)
fmt.Printf(" ParentPath: %s\n", planner.ParentPath())
ds := planner.DataSourceConfiguration()
fmt.Printf("Datasource id: %s name: %s hash: %d\n", ds.Id(), ds.Name(), ds.Hash())
fmt.Printf("Depends on planner ids: %v\n", planner.ObjectFetchConfiguration().dependsOnFetchIDs)
fmt.Printf(" Datasource ID: %s, name: %s, hash: %d\n", ds.Id(), ds.Name(), ds.Hash())
if len(planner.ObjectFetchConfiguration().dependsOnFetchIDs) > 0 {
fmt.Printf(" Depends on planner IDs: %v\n", planner.ObjectFetchConfiguration().dependsOnFetchIDs)
}

requiredFields := planner.RequiredFields()
if requiredFields != nil && len(*requiredFields) > 0 {
fmt.Println("Required fields:")
fmt.Println(" Required fields:")
for _, field := range *requiredFields {
if field.FieldName != "" {
fmt.Printf("required by %s: %s\n", field.FieldName, field)
fmt.Printf(" required by %s: %s\n", field.FieldName, field)
continue
}
fmt.Println("key:", field)
fmt.Println(" key:", field)
}
}
fmt.Println("Paths:")
fmt.Println(" Paths:")
planner.ForEachPath(func(path *pathConfiguration) (shouldBreak bool) {
fmt.Println(path.String())
return false
Expand All @@ -176,9 +180,9 @@ func (p *PathBuilder) printPlanningPaths() {

func (p *PathBuilder) printMissingPaths() {
if p.visitor.hasMissingPaths() {
debugMessage("Missing paths:")
fmt.Printf("\n Missing paths:\n")
for path := range p.visitor.missingPathTracker {
fmt.Println(path)
fmt.Printf(" %v\n", path)
}
}
}
9 changes: 4 additions & 5 deletions v2/pkg/engine/plan/path_builder_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,12 @@ func (c *pathBuilderVisitor) handleMissingPath(planned bool, typeName string, fi
if planned {
// __typename field on a union could not have a suggestion
return
} else {
if c.plannerConfiguration.Debug.PrintPlanningPaths {
fmt.Println("Adding potentially missing path", currentPath)
}
}

c.potentiallyMissingPathTracker[currentPath] = struct{}{}
if c.plannerConfiguration.Debug.PrintPlanningPaths {
fmt.Println("Found potentially missing path", currentPath)
}
c.potentiallyMissingPathTracker[currentPath] = struct{}{}
}

allSuggestionsPlanned := true
Expand Down