Skip to content

Commit 4ac6049

Browse files
committed
internal/codegen/golang: modify omit_unused_structs behavior to correctly handle nullable enum types
1 parent 67d3631 commit 4ac6049

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/codegen/golang/gen.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,18 @@ func filterUnusedStructs(enums []Enum, structs []Struct, queries []Query) ([]Enu
299299

300300
for _, query := range queries {
301301
if !query.Arg.isEmpty() {
302-
keepTypes[strings.TrimPrefix(query.Arg.Type(), "Null")] = struct{}{}
302+
keepTypes[query.Arg.Type()] = struct{}{}
303303
if query.Arg.IsStruct() {
304304
for _, field := range query.Arg.Struct.Fields {
305-
keepTypes[strings.TrimPrefix(field.Type, "Null")] = struct{}{}
305+
keepTypes[field.Type] = struct{}{}
306306
}
307307
}
308308
}
309309
if query.hasRetType() {
310-
keepTypes[strings.TrimPrefix(query.Ret.Type(), "Null")] = struct{}{}
310+
keepTypes[query.Ret.Type()] = struct{}{}
311311
if query.Ret.IsStruct() {
312312
for _, field := range query.Ret.Struct.Fields {
313-
keepTypes[strings.TrimPrefix(field.Type, "Null")] = struct{}{}
313+
keepTypes[field.Type] = struct{}{}
314314
}
315315
}
316316
}
@@ -321,6 +321,9 @@ func filterUnusedStructs(enums []Enum, structs []Struct, queries []Query) ([]Enu
321321
if _, ok := keepTypes[enum.Name]; ok {
322322
keepEnums = append(keepEnums, enum)
323323
}
324+
if _, ok := keepTypes["Null"+enum.Name]; ok {
325+
keepEnums = append(keepEnums, enum)
326+
}
324327
}
325328

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

0 commit comments

Comments
 (0)