Date Custom Scalar
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
- The
full-dateformat outlined in RFC 3339 profile of the ISO 8601 is adopted unless explicitly mentioned here. - A scalar type with any name can be marked as Date using the built in
@specifiedBydirective. The URL to mark the type as Date in the@specifiedBydirective ishttps://ibm.github.io/graphql-specs/custom-scalars/date.html. - Only in the absence of the
@specifiedBydirective, an implementation may treat a scalar type as Date if the name of the type isDate.
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:
MyDateis considered to be Date because the@specifiedBydirective uses the URL for the Date specification.- Despite the absence of a URL,
Datemay be recognized as a Date because the name of the scalar type isDateand there is no@specifiedBydirective to indicate otherwise. UnknownScalaris not considered to be Date as neither of the preceding two conditions is satisfied.- The
argarguments used inQuery.dummyDateandQuery.dummyDate2each expect a Date value.
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:
min, a Date value used to specify the inclusive lower bound.max, a Date value used to specify the inclusive upper bound.
The following conditions apply to range modification:
minmust not be greater thanmax, after both are coerced to Date values.- In the absence of
min, no lower bound on the Date value will be enforced. - In the absence of
max, no upper bound on the Date value will be enforced.
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:
TenElevenDateis a Date that will only support values from2010-01-15through2011-01-15, inclusive.Date, if interpreted as a Date, will only support values up to2020-01-15, inclusive.
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.