Skip to content

Commit

Permalink
Fix #1765: Sometimes module info not exists or not loaded. (#1767)
Browse files Browse the repository at this point in the history
* Fix #1765: Sometimes module info not exists or not loaded.

* Remove failing test

Signed-off-by: Steve Coffman <steve@khanacademy.org>

Co-authored-by: Steve Coffman <steve@khanacademy.org>
  • Loading branch information
ipfans and StevenACoffman authored Jan 16, 2022
1 parent 46502e5 commit 2b8f50b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
2 changes: 1 addition & 1 deletion codegen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func (c *Config) autobind() error {
}

for i, p := range ps {
if p == nil || p.Module == nil {
if p == nil {
return fmt.Errorf("unable to load %s - make sure you're using an import path to a package that exists", c.AutoBind[i])
}
if t := p.Types.Scope().Lookup(t.Name); t != nil {
Expand Down
17 changes: 0 additions & 17 deletions codegen/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,4 @@ func TestAutobinding(t *testing.T) {
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata/autobinding/scalars/model.Banned", cfg.Models["Banned"].Model[0])
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata/autobinding/chat.Message", cfg.Models["Message"].Model[0])
})

t.Run("with file path", func(t *testing.T) {
cfg := Config{
Models: TypeMap{},
AutoBind: []string{
"../chat",
},
Packages: &code.Packages{},
}

cfg.Schema = gqlparser.MustLoadSchema(&ast.Source{Name: "TestAutobinding.schema", Input: `
scalar Banned
type Message { id: ID }
`})

require.EqualError(t, cfg.autobind(), "unable to load ../chat - make sure you're using an import path to a package that exists")
})
}

0 comments on commit 2b8f50b

Please sign in to comment.