Sort operations to guarantee a stable order (#156)

Problem: currently when using a wildcard that covers multiple files in `operations:` YAML directive the generator emits functions in a non-stable ordering due to the use of map for storing file names:

https://github.com/Khan/genqlient/blob/e0accbded177db9143314911bacedf61b2cda656/generate/parse.go#L68-L84

Solution: sort the operations before emitting them.
This commit is contained in:
Nikolay Edigaryev
2021-11-26 23:32:03 +03:00
committed by GitHub
parent 2fdbb629be
commit f80df6d4f1
5 changed files with 445 additions and 329 deletions
+6
View File
@@ -341,6 +341,12 @@ func Generate(config *Config) (map[string][]byte, error) {
if err != nil {
return nil, err
}
// Sort operations to guarantee a stable order
sort.Slice(g.Operations, func(i, j int) bool {
return g.Operations[i].Name < g.Operations[j].Name
})
for _, operation := range g.Operations {
err = g.render("operation.go.tmpl", &bodyBuf, operation)
if err != nil {