[MGNLGQL-83] Support DateTime in GraphQL Created: 12/Apr/21  Updated: 23/Apr/21  Resolved: 16/Apr/21

Status: Closed
Project: Magnolia GraphQL
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0

Type: Improvement Priority: Neutral
Reporter: Jaroslav Simak Assignee: Jaroslav Simak
Resolution: Done Votes: 0
Labels: VN-Testing
Remaining Estimate: Not Specified
Time Spent: 0.75d
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[X]* Doc/release notes changes? Comment present?
[X]* Downstream builds green?
[X]* Solution information and context easily available?
[X]* Tests
[X]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Documentation update required:
Yes
Date of First Response:
Epic Link: GraphQL Phase 1
Sprint: HL & LD 26
Story Points: 2

 Description   

Our GraphQL formats Date(Time) always into yyyy-mm-dd format. We need to support both Date and DateTime.

Plan of action - based on conversation in comments

  • Introduce DateTime scalar which outputs values in 8601 ISO format: yyyy-mm-ddThh:mm:ss:sssZ
  • Change the system (metadata) properties defined by us to be DateTime
  • Keep the current  ContentType "Date" properties as is and have the generated GraphQL types be of scalar "Date" and output yyyy-mm-dd format. This is logical because ContentType-based app also renders a Date picker (not a Date & Time picker)

One corner case we should document:

If one decides to decorate CT generated app and enables time picker, then he/she should also decorate the respective GraphQL definition and set the type of the field to DateTime.

 In the future we plan to add a DateTime property type to ContentTypes system, which will then result in Date Time picker in the app and DateTime output in GraphQL.

 

 

 

Previous Ideas

We have a couple of options here:

  • specify another scalar type, e.g. DateTime
  • introduce a new argument for Date field called format which would take string parameter with requested format.
  • always return date in DateTime format.

Option #2 seems most flexible - devs would not need to hassle with datetime formatting on the client and would get exactly what they want (which imo is the GraphQL way).



 Comments   
Comment by Jaroslav Simak [ 14/Apr/21 ]
  • New GraphQL Scalar provided out of the box - DateTime with ISO8601 format
  • System fields (such as created, lastModified for both jcr content types and assets are now in DateTime
  • Date property type for jcr content types still remains in Date ISO8601 format
Generated at Mon Feb 12 05:52:25 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.