Skip to content

Commit

Permalink
use alias when invalid pkg name
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey1s committed Jul 25, 2019
1 parent 2591ea3 commit fbbed5b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion codegen/templates/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"go/types"
"strconv"
"strings"

"github.com/99designs/gqlgen/internal/code"
)
Expand All @@ -20,7 +21,7 @@ type Imports struct {
}

func (i *Import) String() string {
if i.Alias == i.Name {
if strings.HasSuffix(i.Path, i.Alias) {
return strconv.Quote(i.Path)
}

Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestImports(t *testing.T) {
t,
`"github.com/99designs/gqlgen/codegen/templates/testdata/a/bar"
bar1 "github.com/99designs/gqlgen/codegen/templates/testdata/b/bar"
"github.com/99designs/gqlgen/codegen/templates/testdata/pkg_mismatch"`,
turtles "github.com/99designs/gqlgen/codegen/templates/testdata/pkg_mismatch"`,
a.String(),
)
})
Expand Down
2 changes: 1 addition & 1 deletion integration/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbbed5b

Please sign in to comment.