Skip to content

Commit

Permalink
ensure that self-edges are correctly filtered in reachability analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
benweint committed Jun 4, 2024
1 parent 2c68ac7 commit cfb57fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ func (g *Graph) ReachableFrom(roots []*model.NameReference, maxDepth int) *Graph
for _, edge := range edges {
_, srcPresent := filteredNodes[edge.src.Name]
_, dstPresent := filteredNodes[edge.dst.Name]
if srcPresent && dstPresent {
fieldPresent := edge.field == nil || seen.includesField(edge.src.Name, edge.field.Name)
if srcPresent && dstPresent && fieldPresent {
filtered = append(filtered, edge)
}
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ func TestReachableFrom(t *testing.T) {
},
},
},
{
name: "filtered self edges",
schema: `type Person {
hobbies: [Hobby]
friends: [Person]
}
type Hobby {
name: String
}
`,
roots: []string{"Person.hobbies"},
maxDepth: 2,
expectedNodes: []string{"Hobby", "Person"},
expectedFields: []string{"Hobby.name", "Person.hobbies"},
expectedEdges: []edgeSpec{
{
srcType: "Person",
dstType: "Hobby",
fieldName: "hobbies",
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
src := ast.Source{
Expand Down

0 comments on commit cfb57fa

Please sign in to comment.