Skip to content

Commit

Permalink
make types in union deterministic (#1855)
Browse files Browse the repository at this point in the history
  • Loading branch information
lolopinto authored Nov 18, 2024
1 parent f004b22 commit 242adad
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/graphql/custom_ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package graphql
import (
"fmt"
"path/filepath"
"sort"
"strings"

"github.com/lolopinto/ent/internal/codegen"
Expand Down Expand Up @@ -1090,6 +1091,8 @@ func processCustomUnions(processor *codegen.Processor, cd *CustomData, s *gqlSch

unionTypes := make([]string, len(union.UnionTypes))
imports := make([]*tsimport.ImportPath, len(union.UnionTypes))
// sort to make sure it's deterministic
sort.Strings(union.UnionTypes)
for i, unionType := range union.UnionTypes {
unionTypes[i] = fmt.Sprintf("%sType", unionType)
imports[i] = tsimport.NewLocalGraphQLEntImportPath(unionType)
Expand Down
2 changes: 2 additions & 0 deletions internal/graphql/generate_ts_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,8 @@ func buildGQLSchema(processor *codegen.Processor) chan *buildGQLSchemaResult {

unionTypes := make([]string, len(nodeNames))
imports := make([]*tsimport.ImportPath, len(nodeNames))
// sort for deterministic output
sort.Strings(nodeNames)
for i, nodeName := range nodeNames {
unionTypes[i] = fmt.Sprintf("%sType", nodeName)
imports[i] = tsimport.NewLocalGraphQLEntImportPath(nodeName)
Expand Down

1 comment on commit 242adad

@Swahvay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omg thank you. I didn't want to bug you on this one since it wasn't really a problem, but it was a little annoying having them swap orders all the time.

Please sign in to comment.