Skip to content

Commit

Permalink
internal/codegen/golang: modify omit_unused_structs behavior to corre…
Browse files Browse the repository at this point in the history
…ctly handle nullable enum types
  • Loading branch information
andrewmbenton committed Jun 27, 2023
1 parent dab7e0e commit 4454e78
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/codegen/golang/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,18 @@ func filterUnusedStructs(enums []Enum, structs []Struct, queries []Query) ([]Enu

for _, query := range queries {
if !query.Arg.isEmpty() {
keepTypes[strings.TrimPrefix(query.Arg.Type(), "Null")] = struct{}{}
keepTypes[query.Arg.Type()] = struct{}{}
if query.Arg.IsStruct() {
for _, field := range query.Arg.Struct.Fields {
keepTypes[strings.TrimPrefix(field.Type, "Null")] = struct{}{}
keepTypes[field.Type] = struct{}{}
}
}
}
if query.hasRetType() {
keepTypes[strings.TrimPrefix(query.Ret.Type(), "Null")] = struct{}{}
keepTypes[query.Ret.Type()] = struct{}{}
if query.Ret.IsStruct() {
for _, field := range query.Ret.Struct.Fields {
keepTypes[strings.TrimPrefix(field.Type, "Null")] = struct{}{}
keepTypes[field.Type] = struct{}{}
}
}
}
Expand All @@ -321,6 +321,9 @@ func filterUnusedStructs(enums []Enum, structs []Struct, queries []Query) ([]Enu
if _, ok := keepTypes[enum.Name]; ok {
keepEnums = append(keepEnums, enum)
}
if _, ok := keepTypes["Null"+enum.Name]; ok {
keepEnums = append(keepEnums, enum)
}
}

keepStructs := make([]Struct, 0, len(structs))
Expand Down

0 comments on commit 4454e78

Please sign in to comment.