Make output deterministic for graphql interfaces (#209)

We noticed that the output from genqlient can be non-deterministic
when a graphql query queries a field that's an interface. This PR
fixes that by sorting the types as soon as we extract them from
the schema.
This commit is contained in:
Viktor Stanchev
2022-07-28 16:19:53 -07:00
committed by GitHub
parent 03b6b6b5d1
commit 2ae8ea42e5
14 changed files with 529 additions and 524 deletions
+3
View File
@@ -11,6 +11,7 @@ package generate
import (
"fmt"
"sort"
"github.com/vektah/gqlparser/v2/ast"
)
@@ -465,6 +466,8 @@ func (g *generator) convertDefinition(
}
implementationTypes := g.schema.GetPossibleTypes(def)
// Make sure we generate stable output by sorting the types by name when we get them
sort.Slice(implementationTypes, func(i, j int) bool { return implementationTypes[i].Name < implementationTypes[j].Name })
goType := &goInterfaceType{
GoName: name,
SharedFields: sharedFields,