add omitempty

This commit is contained in:
Ben Kraft
2021-04-09 11:51:30 -07:00
parent 25a2b45ccc
commit 16523c1f81
8 changed files with 246 additions and 14 deletions
+11 -1
View File
@@ -24,9 +24,19 @@ func {{.Name}}(
{{- if .Args -}}
variables := map[string]interface{}{
{{range .Args -}}
"{{.GraphQLName}}": {{.GoName}},
"{{.GraphQLName}}": {{if .Omitempty}}nil{{else}}{{.GoName}}{{end}},
{{end}}
}
{{range .Args -}}
{{if .Omitempty -}}
{{/* 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}} {
variables["{{.GraphQLName}}"] = {{.GoName}}
}
{{end}}
{{end}}
{{end}}
var retval {{.ResponseName}}
err := {{if $.Config.ClientGetter}}{{$.Config.ClientGetter}}{{else}}client{{end}}.MakeRequest(