-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide support for Jiff date/time types #1270
Comments
Jiff author here. Great to see this! Happy to answer questions. :-) For With that said, if your datetimes do not have a time zone ID in them, and GraphQL cannot otherwise store them, then probably the right thing to do is to not offer The idea with a Everything else looks correct to me, including the mapping from Jiff's civil date types to GraphQL's local data types. (With the caveat that I don't know too much about GraphQL. But the docs you linked all seem like they support the mapping you chose here.) |
@BurntSushi Wow, didn't expect you to notice this already. Nice to see you here, and thank you so much for making Jiff 🙂 I can see two potential issues from my putting together a PR for this feature:
Both of these lose data when going through GraphQL scalars. I guess we need to decide whether this can be tolerated. |
|
In my current draft, I am rounding manually. The need to handle errors is unfortunate, but since these can happen only for configuration errors (which we can rule out), there should be no problems at runtime. Regarding the principle decision to not allow sub-millisecond resolution, I have opened an issue upstream.
I am wondering how we would try to document this. It seems rather subtle to force users to make sure to use properly fixed Thus, I tend to agree with your initial assessment above and would probably indeed not offer serialization for |
Yeah that works. You could also drop the rounding if you're okay with truncation, which is what the
Holding off on a |
I was unable to do this. It seems the format specifier sets only the minimum number of digits but does not limit the maximum number of digits. I opened BurntSushi/jiff#73 for tracking this separately (but I don't think supporting this would be absolutely necessary, so feel free to comment there or even close that issue if this would make formatting too complex).
My worries are that the caller has no control over this. Assume they are running a GraphQL query and (at runtime) the Then the code would still compile as usual but now querying this attribute in a GraphQL type would suddenly fail. But, taking a step back, this might all come down to what the transport serialization is able to express anyway: Since we as developers explicitly decide on what target format to use (e.g. GraphQL scalar In another environment where the client side supports it, developers could then explicitly settle on using an RFC 9557 serializer type instead for any This is similar to the restrictions of Unfortunately, I am not aware of an easy way to tell Juniper to use different serialization formats for the same underlying type, other than using newtypes or explicitly rolling out custom conversions—which kind of counters the first-class support for these types that we are trying to add in this PR. To enable an easy upgrade path to RFC 9557 serialization when a matching GraphQL scalar is added, I see two possibilities:
Footnotes
|
Gotya. Yeah I'm not especially familiar with GraphQL, but I think what you're saying there makes sense. I think it would be good to leave out |
The fact that https://graphql-scalars.dev/docs/scalars/ collection doesn't provide such a scalar is not a blocker as for me. We just can introduce the So, additional PR is welcome! |
- represent `jiff::civil::Date` as `LocalDate` GraphQL scalar - represent `jiff::civil::Time` as `LocalTime` GraphQL scalar - represent `jiff::civil::DateTime` as `LocalDateTime` GraphQL scalar - represent `jiff::Timestamp` as `DateTime` GraphQL scalar - represent `jiff::Span` as `Duration` GraphQL scalar
Thank you for giving the go here. I have opened #1278. |
Description
This is a proposal to add first-class support for the data types from Jiff. First-class support is necessary, and an external crate would be much more inconvenient to use, because of Rust's orphan rule as outlined in #87 (comment).
This should cover the following date/time types:
Timestamps
Timestamp
, serialized as RFC 3339 (ISO 8601) date/time with UTC time zone, GraphQL scalarDateTime
, e.g.2024-06-19T19:22:45Z
Zoned
, serialized as RFC 9557 date/time with time zone, GraphQL scalarZonedDateTime
1, e.g.2024-07-04T08:39:00-04:00[America/New_York]
Wall-clocked
Date
, serialized as date, without time zone, GraphQL scalarLocalDate
, e.g.2024-06-19
Time
, serialized as time, without time zone, GraphQL scalarLocalTime
, e.g.15:22:45
DateTime
, serialized as date/time, without time zone, GraphQL scalarLocalDateTime
, e.g.2024-06-19T15:22:45
Durations
Span
, serialized as ISO 8601 duration, GraphQL scalarDuration
, e.g.P5dT8h1m
Time zones
TimeZone
, serialized as IANA time zone identifier, GraphQL scalarTimeZone
, e.g.America/New_York
Where types overlap, the resulting serialization would be identical to the one for the
chrono
andtime
crates, with the difference of using GraphQL scalarLocalDate
instead ofDate
.2I am aware that Jiff is a very new library but I think it has great potential in the ecosystem. Having dealt with date/time intricacies in several projects, I regard it as one of the top-contenders for following or eventually even superseding
chrono
/time
.I am willing to provide a PR if this proposal is accepted.See #1271 for a PR that implements these features.See #1272 for a PR that adds support for the types
Zoned
andTimeZone
.Footnotes
This always includes the time zone specifier and uses RFC
85369557. This format seems not widely used yet. It is also not a valid input for GraphQL scalarDateTime
, therefore we serialize it as the GraphQL scalarZonedDateTime
which has not been stabilized, or even defined elsewhere, yet. ↩LocalDate
seems to be the more appropriate type. I am not sure whychrono
andtime
integration chose to useDate
instead. ↩The text was updated successfully, but these errors were encountered: