Skip to content

Commit

Permalink
Merge pull request #1526 from epulze/fix/allow-more-types
Browse files Browse the repository at this point in the history
allow more than 10 different import sources with types
  • Loading branch information
lwc authored Sep 8, 2021
2 parents e7df3e5 + e82b401 commit 1e2b303
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codegen/templates/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *Imports) Lookup(path string) string {
for s.findByAlias(alias) != nil {
alias = imp.Name + strconv.Itoa(i)
i++
if i > 10 {
if i > 1000 {
panic(fmt.Errorf("too many collisions, last attempt was %s", alias))
}
}
Expand Down
14 changes: 14 additions & 0 deletions codegen/templates/import_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package templates

import (
"fmt"
"go/types"
"os"
"testing"
Expand Down Expand Up @@ -45,6 +46,19 @@ func TestImports(t *testing.T) {
})
})

t.Run("duplicates above 10 are decollisioned", func(t *testing.T) {
a := Imports{destDir: wd, packages: &code.Packages{}}
for i := 0; i < 100; i++ {
cBar := fmt.Sprintf("github.com/99designs/gqlgen/codegen/templates/testdata/%d/bar", i)
if i > 0 {
require.Equal(t, fmt.Sprintf("bar%d", i), a.Lookup(cBar))
} else {
require.Equal(t, "bar", a.Lookup(cBar))

}
}
})

t.Run("package name defined in code will be used", func(t *testing.T) {
a := Imports{destDir: wd, packages: &code.Packages{}}

Expand Down

0 comments on commit 1e2b303

Please sign in to comment.