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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user