Date Custom Scalar

Note This document is a DRAFT. It is being published to solicit feedback. It is a “live document” that can change whenever feedback is given and accepted.

This draft is © Copyright IBM Corp. 2022.

1Goals

This specification defines the custom scalar type Date that is useful for specifying dates. This specification is based on RFC 3339 profile of the ISO 8601.

Note: All mentions of Date refer to the scalar type defined by this specification. All mentions of Date refer to a user-declared scalar name.

2Definition

3Example of the Date Type

The following example uses Date:

Example № 1scalar MyDate @specifiedBy (url: "https://ibm.github.io/graphql-specs/custom-scalars/date.html")
scalar Date
scalar UnknownScalar

type Query {  
  dummyDate(arg: MyDate): Int
  dummyDate2(arg: Date): Int
}

schema {
  query: Query
}

In this example, the following points should be noted:

This is a simple example query that matches the schema:

Example № 2query example {
    dummyDate (arg: "2010-10-24")
}

4Customizing the Date Type

The lower and upper bounds of Date can be changed via the @scalarParam directive as defined here. The parameters used in the @scalarParam directive to specify the bounds are:

The following conditions apply to range modification:

5Example of Date Type Customization

The following example demonstrates how to modify the range of Date using the @scalarParam directive:

Example № 3directive @scalarParam (name: String!, value: String!) repeatable on SCALAR

scalar TenElevenDate @specifiedBy (url: "https://ibm.github.io/graphql-specs/custom-scalars/date.html") 
                         @scalarParam (name: "min", value: "2010-01-15") 
                         @scalarParam (name: "max", value: "2011-01-15")

scalar Date @scalarParam (name: "max", value: "2020-01-15")

type Query {  
  dummyDate(arg: TenElevenDate): Int
  dummyDate2(arg: Date): Int
}

schema {
  query: Query
}

In this example, the following points should be noted:

6Result Coercion

Input

Only a string formatted as a valid Date is accepted.

Output

The output value is a string formatted as a valid Date.

7Literal Coercion

Input

Only a string formatted as a valid Date is accepted.

Output

The output value is a string formatted as a valid Date.

8Value Coercion

Input

Only a string formatted as a valid Date is accepted.

Output

The output value is a string formatted as a valid Date.

  1. 1Goals
  2. 2Definition
  3. 3Example of the Date Type
  4. 4Customizing the Date Type
  5. 5Example of Date Type Customization
  6. 6Result Coercion
  7. 7Literal Coercion
  8. 8Value Coercion