Spring Boot GraphQL Tutorial #17 - Date Type

Опубликовано: 19 Октябрь 2024
на канале: Philip Starritt
8,336
70

Here we implement the DateTime and Date custom scalar types implemented by graphql java extended scalars.

The graphql specification does not define a Date Type or DateTime type due to too many opinions and requirements. This is why we need to define our own custom scalar. Lucky for us there are already two great libraries providing date related scalars: graphql-java-extended-scalars and graphql-java-datetime.


graphql-java-datetime provides a greater range of date scalars such as:

java.util.Date implementation:
scalar Date

java.time.LocalDate implementation:
scalar LocalDate

java.time.LocalDateTime implementation:
scalar LocalDateTime

java.time.LocalTime implementation:
scalar LocalTime

java.time.OffsetDateTime implementation:
scalar OffsetDateTime

java.time.YearMonth implementation:
scalar YearMonth

java.time.Duration implementation:
scalar Duration





DateTime Scalars provided by extended scalars (graphql-java-extended-scalars):

DateTime:
An RFC-3339 compliant date time scalar that accepts string values like 1996-12-19T16:39:57-08:00 and produces java.time.OffsetDateTime objects at runtime.

Time:
An RFC-3339 compliant time scalar that accepts string values like 16:39:57-08:00 and produces java.time.OffsetTime objects at runtime.

Date:
An RFC-3339 compliant date scalar that accepts string values like 1996-12-19 and produces java.time.LocalDate objects at runtime.

See you in the next tutorial where I give an example of graphql java bean validation.

Thanks!
Philip


GraphQL open issue for standardizing Date and DateTime scalar: https://github.com/graphql/graphql-sp...

GraphQL datetime closed issue: https://github.com/graphql/graphql-sp...

Spring Boot GraphQL: https://github.com/graphql-java-kicks...

Introduction to extended scalars: https://www.graphql-java.com/blog/int...

GraphQL Java Date Scalar Library (graphql-java-datetime): https://github.com/donbeave/graphql-j...

Java Extended scalars github: https://github.com/graphql-java/graph...