Skip to content

GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphql-java.

License

Notifications You must be signed in to change notification settings

efimmatytsin/graphql-java-datetime

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-java-datetime · License PRs Welcome

GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphql-java.

Build Status Latest Dev Build

Summary

A set of ISO 33601, RFC 3339 compatible date time scalars for GraphQL Java implementation (graphql-java) and GraphQL Java Kickstart (com.graphql-java-kickstart:graphql-spring-boot-starter).

Serialization

java.util.Date, java.time.LocalDate, java.time.LocalDateTime

Format                   JSON String
yyyy-MM-dd'T'HH:MM:ss.SSS'Z' 2017-07-09T13:14:45.947Z
yyyy-MM-dd'T'HH:MM:ss'Z' 2017-07-09T11:54:42Z
yyyy-MM-dd'T'HH:MM:ss 2017-07-09T11:54:42
yyyy-MM-dd 2017-07-09

java.time.LocalTime

Format       JSON String
HH:MM:ss.SSS 17:59:59.129
HH:MM:ss 17:59:59
HH:MM 17:59

Usage

Spring Boot

Add graphql-datetime-spring-boot-starter or graphql-datetime-spring-boot-starter-webflux starter (according to your spring boot stack) to your project first.

Installation

Maven

Add folowing to your pom.xml:

for Spring MVC:

<dependency>
  <groupId>com.zhokhov.graphql</groupId>
  <artifactId>graphql-datetime-spring-boot-starter</artifactId>
  <version>2.1.0</version>
</dependency>

or

for Spring WebFlux:

<dependency>
  <groupId>com.zhokhov.graphql</groupId>
  <artifactId>graphql-datetime-spring-boot-starter-webflux</artifactId>
  <version>2.1.0</version>
</dependency>

Gradle

Add folowing to your build.gradle:

for Spring MVC:

implementation("com.zhokhov.graphql:graphql-datetime-spring-boot-starter:2.1.0")

or

for Spring WebFlux:

implementation("com.zhokhov.graphql:graphql-datetime-spring-boot-starter-webflux:2.1.0")

Scalars

Add these scalars to your .graphqls schema file:

# 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 

# YearMonth implementation
scalar java.time.YearMonth

You can rename the scalar however you want with by simply adding the following properties to you application.yaml:

graphql:
  datetime:
    scalars:
      date:
        scalarName: MyDate
      localDate:
        scalarName: MyLocalDate
      localDateTime:
        scalarName: MyLocalDateTime
      localTime:
        scalarName: MyLocalTime
      offsetDateTime:
        scalarName: MyOffsetDateTime
      yearMonth:
        scalarName: MyYearMonth

A custom format can be set for LocalDate and LocalDateTime only using the following properties in application.yaml

graphql:
  datetime:
    scalars:
      localDate:
        format: MM/dd/yyyy
      localDateTime:
        format: yyyy-MM-dd'T'HH:mm:ss

You can enable automatic zone conversion by adding the following property to your application.yaml. This will automatically convert between UTC and the default TimeZone for LocalDateTime:

graphql:
  datetime:
    scalars:
      zone-conversion-enabled: true

If using OffsetDateTime in order to present the offset and disable the automatic convertion to UTC from Jackson you should set to your application.yml the following:

spring:
  jackson:
    deserialization:
      adjust-dates-to-context-time-zone: false

Sample

Now you can use these scalars in your application. Here is graphql-datetime spring boot sample applications:

Bugs

To report any bug, please use the project Issues section on GitHub.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

License

Copyright © 2017-2020 Alexey Zhokhov. All rights reserved.

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

About

GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphql-java.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 56.4%
  • Groovy 40.8%
  • Shell 2.8%