Skip to content
GraphQL ISO Date is a set of RFC 3339 compliant date/time scalar types to be used with graphql-java.
Java Groovy Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper Gradle 5.2.1. Feb 14, 2019
graphql-datetime-autoconfigure updating versions for compatibility with graphql-spring-boot-starter 6 Dec 6, 2019
graphql-datetime-sample-app Dependencies up. Mar 2, 2019
graphql-datetime-spring-boot-starter Initial version of date time scalars for graphql-java. Jul 10, 2017
graphql-java-datetime Apply zone conversion parsing LocalDate (fix #14) Mar 1, 2019
.gitignore Initial version of date time scalars for graphql-java. Jul 10, 2017
.travis.yml Use openjdk8 instead of oraclejdk8 in build Dec 10, 2019
LICENSE
README.md Update README.md Dec 11, 2019
build.gradle Code format. Feb 14, 2019
build.sh Format. Jul 11, 2018
check-dependency-updates.sh
gradle.properties updating project version Dec 6, 2019
gradlew Gradle 5.1.1. Jan 12, 2019
gradlew.bat Gradle 5.1.1. Jan 12, 2019
refresh-dependencies.sh Tests fixed. Jul 27, 2018
settings.gradle Added sample app. Jul 14, 2017
test.sh Code format. Jul 11, 2018
version.sh Update some dependencies. Jul 11, 2018

README.md

graphql-java-datetime

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).

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 starter to your project first.

Installation

Maven

Add folowing to your pom.xml:

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

Gradle

Add folowing to your build.gradle:

compile 'com.zhokhov.graphql:graphql-datetime-spring-boot-starter:1.6.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

# javal.time.OffsetDateTime implementation
scalar OffsetDateTime 

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

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 a graphql-datetime spring boot sample application, https://github.com/donbeave/graphql-java-datetime/tree/master/graphql-datetime-sample-app.

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-2018 Alexey Zhokhov. All rights reserved.

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

You can’t perform that action at this time.