diff --git a/codegen/templates/import.go b/codegen/templates/import.go index effe9a0dfb..d5bd16a6a1 100644 --- a/codegen/templates/import.go +++ b/codegen/templates/import.go @@ -4,6 +4,7 @@ import ( "fmt" "go/types" "strconv" + "strings" "github.com/99designs/gqlgen/internal/code" ) @@ -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) } diff --git a/codegen/templates/import_test.go b/codegen/templates/import_test.go index b055beb724..d225457576 100644 --- a/codegen/templates/import_test.go +++ b/codegen/templates/import_test.go @@ -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(), ) }) diff --git a/integration/generated.go b/integration/generated.go index 20c41fe8cc..bcbe243707 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -12,7 +12,7 @@ import ( "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" - "github.com/99designs/gqlgen/integration/models-go" + models "github.com/99designs/gqlgen/integration/models-go" "github.com/99designs/gqlgen/integration/remote_api" "github.com/vektah/gqlparser" "github.com/vektah/gqlparser/ast"