Skip to content

Commit

Permalink
Fix non-deterministic generated code involving interfaces and fragments.
Browse files Browse the repository at this point in the history
In #209, @vikstrous2 added a bugfix to sort the list of interfaces
when generating code, so the generated output was stable.  This worked
great, but there was one more case where we need to do that, involving
interfaces in fragments.
  • Loading branch information
csilvers committed Feb 26, 2024
1 parent ae275ac commit cd71e53
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ Note that genqlient is now tested from Go 1.20 through Go 1.22.
### Bug fixes:
- The presence of negative pointer directives, i.e., `# @genqlient(pointer: false)` are now respected even in the when `optional: pointer` is set in the configuration file.
- Made name collisions between query/mutation arguments and local function variables less likely.
- Fix generation issue related to golang type implementation of complex graphql union fragments
- Fix generation issue related to golang type implementation of complex graphql union fragments.
- Bind correctly to types in the same package as the generated code.
- Fix non-deterministic generated code when querying graphql interfaces via named fragments.

## v0.6.0

Expand Down
2 changes: 2 additions & 0 deletions generate/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ func (g *generator) convertNamedFragment(fragment *ast.FragmentDefinition) (goTy
return goType, nil
case ast.Interface, ast.Union:
implementationTypes := g.schema.GetPossibleTypes(typ)
// 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: fragment.Name,
SharedFields: fields,
Expand Down

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.

0 comments on commit cd71e53

Please sign in to comment.