omitempty
does not work on time.Time
structs.
See https://lists.sr.ht/~emersion/hut-dev/%3C20220218135156.614905-1-contact%40emersion.fr%3E
Does this only apply to the referenced patch? It seems like the issue in that patch can be traced to this value.
It seems to me like gqlclient shouldn’t have to handle nullable structs, but that inputs should marshal to json properly on their own. In this case, changing time.Time to *time.Time should fix SubmitTicketInput.
I haven’t looked much deeper than that though so I recognize this might be shortsighted.
Indeed, we already handle nullable structs. We special-case
time.Time
because it has a natural "no value" representation: the zero time. Using a nil*time.Time
isn't very idiomatic.
The time documentation recommends that it should typically not be passed as a pointer and that IsZero can be used to determine uninitialized times. But if there are indeed legitimate use-cases where you would use the zero value, then time should probably be removed from this case. Otherwise the backend has to check with
IsZero
.
The ideal solution is to use the
time.Time
zero value to represent a GQL null value, and marshal it as "null" on the wire. It's more difficult to implement.
This was implemented in ccaba8ec.