Skip to content

Commit

Permalink
feat: always set omitempty on pointer fields
Browse files Browse the repository at this point in the history
  • Loading branch information
obitech committed Jul 27, 2023
1 parent 0aa03e9 commit 83dcc0b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion generate/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,20 @@ func (g *generator) convertDefinition(
return nil, err
}

// We always want to set omitempty if the field is a pointer, unless
// the user explicitly wants the value to be sent as null.
omitEmpty := fieldOptions.GetOmitempty()
if options.GetPointer() && (!field.Type.NonNull && g.Config.Optional == "pointer") && fieldOptions.Omitempty == nil {
omitEmpty = true
}

goType.Fields[i] = &goStructField{
GoName: goName,
GoType: fieldGoType,
JSONName: field.Name,
GraphQLName: field.Name,
Description: field.Description,
Omitempty: fieldOptions.GetOmitempty(),
Omitempty: omitEmpty,
}
}
return goType, nil
Expand Down

0 comments on commit 83dcc0b

Please sign in to comment.