gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

Generate groups and reorders imports incorrectly

Open mdakovac opened this issue 9 months ago • 3 comments

gqlgen version: v0.17.66 go version: 1.23.3

full repro: https://github.com/mdakovac/gqlgen-import-sorting/tree/main

Go lets you group imports by separating them with a newline, however when you run the generate command, this grouping is broken.

import statement before generate in graph/schema.resolvers.go file

import (
	"context"
	"fmt"

	"github.com/rs/zerolog"

	"github.com/example/gqlgen-import-sorting/graph/model"
	"github.com/spf13/viper"
)

after generate

import (
	"context"
	"fmt"

	"github.com/example/gqlgen-import-sorting/graph/model"
	"github.com/rs/zerolog"
	"github.com/spf13/viper"
)

mdakovac avatar Mar 11 '25 13:03 mdakovac

Which file is getting altered in this way?

StevenACoffman avatar Mar 13 '25 10:03 StevenACoffman

graph/schema.resolvers.go is the file, added to description

mdakovac avatar Mar 13 '25 11:03 mdakovac

Thanks! That is irksome, and I'm not sure why that is happening. If you care to make a PR to fix it, I would appreciate it. I would have thought this would have been the result:

import (
	"context"
	"fmt"

	"github.com/rs/zerolog"
	"github.com/spf13/viper"

	"github.com/example/gqlgen-import-sorting/graph/model"
)

StevenACoffman avatar Mar 13 '25 11:03 StevenACoffman