Skip to content

Commit

Permalink
fix: schema import walk wasn't calling next()
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Nov 9, 2023
1 parent 01ce2c3 commit 601af66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backend/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/alecthomas/errors"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/repr"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -237,6 +238,7 @@ func (m *Module) Imports() []string {
_ = Visit(m, func(n Node, next func() error) error {
switch n := n.(type) {
case *DataRef:
repr.Println(n)
if n.Module != "" && n.Module != m.Name {
imports[n.Module] = true
}
Expand All @@ -248,7 +250,7 @@ func (m *Module) Imports() []string {

default:
}
return nil
return next()
})
return maps.Keys(imports)
}
Expand Down
13 changes: 13 additions & 0 deletions backend/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ module todo {
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(schema.String()))
}

func TestImports(t *testing.T) {
input := `
module test {
data Data {
ref other.Data
}
}
`
schema, err := ParseModuleString("", input)
assert.NoError(t, err)
assert.Equal(t, []string{"other"}, schema.Imports())
}

func TestVisit(t *testing.T) {
expected := `
Schema
Expand Down

0 comments on commit 601af66

Please sign in to comment.