In types.js, dates are serialized using String(...); however it's more convenient to deal with dates in ISO8601 format. I understand JavaScript's native toISOString strips the timezone information, so it's not suitable. However, an ISO8601-compliant date formatter could be implemented in a few lines of code using getTimezoneOffset(). Would you be open to a pull request to change the date format? (It's a breaking change, so maybe this is something to put in version 2?)
Yep, open a PR so I can see how you'd like it. To note, I'm just using the native PostgreSQL format so also check out pg-types. In the meantime you can use pg-types parser override mechanism to transform dates into whatever form you want and that should flow through PostGraphQL 馃憤
Another option, which may be better is we turn date types into objects. That way we can expose fields for minutes, hours, and seconds as well as exposing fields for popular formats like iso and utility fields like lessThen, delta, etc. This may be less ergonomic, but has some interesting upsides. What do you think?
Another variant acceptable for me is javascript timestamp, represented by number in millis in similar way as UNIX timestamp..
If this can be configurable it will be awesome
I like the idea of making a few of these formats available, e.g.:
const thing = {
title: "My Thing",
myDate: {
iso: date.toISOString(),
unix: +date/1000,
string: moment(iso).format(),
timezone: date.getTimezoneOffset(),
hours: date.getHours(),
utcHours: date.getUTCHours(),
...
}
}
but I'm not sure how well this meshes with a mutation to update it UpdateThing(myThing.rowId, {newTitle: "This Thing Is My Thing", newMyDate: newDate}). I also think doing this may be over-reaching - chances are the user's going to have to implement some custom logic of the top of this anyway; maybe it's better to just do an ISO8601 with timezone string and let the user worry about formatting it.
Good point about updating. If we wanted though we could accept an ISO string and a unix timestamp integer when updating and switch on type (of course that wouldn鈥檛 be available in output).
Also, a super quick Google Search finds this SO answer recommending ISO 8601, so I鈥檓 down with it.
I鈥檓 going to close this as its in the PostGraphQL 2.0 beta 馃帀
Start playing with the pre-release, the final release should be out really soon. Tell me what you think! :+1:
npm install -g postgraphql@next
postgraphql
Most helpful comment
Heh, I should have posted this earlier:
https://xkcd.com/1179/