diff --git a/backend/schema/schema.go b/backend/schema/schema.go index 60707db670..3045d17391 100644 --- a/backend/schema/schema.go +++ b/backend/schema/schema.go @@ -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" ) @@ -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 } @@ -248,7 +250,7 @@ func (m *Module) Imports() []string { default: } - return nil + return next() }) return maps.Keys(imports) } diff --git a/backend/schema/schema_test.go b/backend/schema/schema_test.go index 34a168a7c9..169eecf5bc 100644 --- a/backend/schema/schema_test.go +++ b/backend/schema/schema_test.go @@ -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