Handle omitempty correctly for slices
We were generating broken code; fixes #43. Also fixes a bug where
applying omitempty to the entire query was broken by e597cac74c.
This commit is contained in:
@@ -31,10 +31,14 @@ func {{.Name}}(
|
||||
}
|
||||
{{range .Args -}}
|
||||
{{if .Options.GetOmitempty -}}
|
||||
{{if .IsSlice -}}
|
||||
if len({{.GoName}}) > 0 {
|
||||
{{else -}}
|
||||
{{/* zero_{{.GoType}} would be a better name, but {{.GoType}} would require
|
||||
munging since it might be, say, `time.Time`. */}}
|
||||
var zero_{{.GoName}} {{.GoType}}
|
||||
if {{.GoName}} != zero_{{.GoName}} {
|
||||
{{end -}}
|
||||
variables["{{.GraphQLName}}"] = {{.GoName}}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user