Fluent Commerce Logo
Docs

GraphQL Date Utilities

Essential knowledge

Intended Audience:

Technical User

Author:

Kirill Gaiduk

Changed on:

24 June 2025

Overview

The `GqlDateUtils` class in the `util-core` bundle provides a simple and effective set of functions for handling the specific date format required by the Fluent Commerce GraphQL API. The platform uses the ISO 8601 format (`yyyy-MM-dd'T'HH:mm:ss.SSS'Z'`), and this utility ensures you can easily parse and format dates to be compatible.

Key points

  • GraphQL Compatibility: This utility ensures that dates are always in the precise ISO 8601 string format required by the Fluent Commerce GraphQL API (`yyyy-MM-dd'T'HH:mm:ss.SSS'Z'`).
  • Parsing (`parseGqlDate`): Safely parses a string from an event or external system into a standard Java `Date` object, preventing common parsing errors.
  • Formatting (`toGqlDate`): Converts a Java `Date` object into the specific string format required when passing dates as variables in GraphQL queries or mutations.
  • Centralized Logic: Centralizes date handling to avoid bugs and ensure consistency across your entire implementation.

Key Concepts

GraphQL APIs require a precise string format for `DateTime` fields. This utility centralizes the logic for converting to and from this format, preventing common errors related to date parsing and formatting.The standard format is: `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'`
  • Example: `2023-10-27T10:30:00.123Z`

Core Methods

`parseGqlDate`
This method parses an object into a standard Java `Date`. It is designed to be flexible and can handle two types of input:
  • A `java.util.Date` object (which it will simply pass through).
  • A `String` that is in the correct GraphQL date format.
This is particularly useful when receiving dates from external systems or in event attributes, which may be in string format.
`toGqlDate`
To parse a `Date` object into a `String` with the format `"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"`, use the `GqlDateUtils.toGqlDate` method:
`getFormat`
To retrieve the date format used by GraphQL, which is `"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"`, use the `GqlDateUtils.getFormat` method: