Registry / database / graphql-iso-date

graphql-iso-date

JSON →
library3.6.1jsnpmunverified

A set of RFC 3339 compliant date/time GraphQL scalar types (Date, Time, DateTime) for use with graphql-js. Version 3.6.1 is the latest stable release. The library has a slow release cadence with few updates. It provides simple ISO 8601 parsing and serialization, unlike graphql-scalars which offers a broader set.

npm install graphql-iso-date
INSTALL
IMPORT
SIG · GRAPHQL-ISO-DATE
G
graphql-iso-date
databasejavascriptv3.6.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GraphQLDate
import { GraphQLDate } from 'graphql-iso-date'
import GraphQLDate from 'graphql-iso-date'
Named export, not default export.
GraphQLTime
import { GraphQLTime } from 'graphql-iso-date'
const { GraphQLTime } = require('graphql-iso-date')
ESM import works; CJS require works too.
GraphQLDateTime
import { GraphQLDateTime } from 'graphql-iso-date'

Creates a GraphQL schema with three scalar fields (Date, Time, DateTime) using graphql-iso-date and executes a query.

import { graphql, GraphQLObjectType, GraphQLSchema } from 'graphql'; import { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date'; const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { birthdate: { type: GraphQLDate, resolve: () => new Date(1991, 11, 24) }, openingNYSE: { type: GraphQLTime, resolve: () => new Date(Date.UTC(2017, 0, 10, 14, 30)) }, instant: { type: GraphQLDateTime, resolve: () => new Date(Date.UTC(2017, 0, 10, 21, 33, 15, 233)) } } }) }); const query = `{ birthdate openingNYSE instant }`; graphql(schema, query).then(result => console.log(result));
Debug
Known issues
gotchaThe resolvers return strings in UTC, not local time. Date and Time are always serialized as UTC.
fix
Ensure your resolvers provide UTC values or manually convert.
affects: >=0.0.0
gotchaThe library only supports parsing strings in strict RFC 3339 format; invalid formats throw errors.
fix
Validate input strings before passing to resolvers.
affects: >=0.0.0
gotchaGraphQLDate scalar coerces Date objects and valid date strings, but does not accept Unix timestamps.
fix
Convert timestamps to Date objects before returning.
affects: >=0.0.0
deprecatedThe peer dependency range includes very old graphql versions (^0.5.0 ... ^0.13.0, ^14.0.0). It may not work with graphql v15+ due to potential breaking changes in scalar specification.
fix
Use graphql ^14.0.0 or ^0.13.0, or migrate to graphql-scalars package for broader compatibility.
affects: >=3.6.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'kind')
Using GraphQLDate with older graphql versions that don't have GraphQLScalarType.KIND or similar
fix
Ensure graphql peer dependency is within supported range: ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0
Expected value of type "DateTime" but received: ...
Resolver returned a non-serializable value (e.g., a number or invalid date string)
fix
Return a Date object, a valid RFC 3339 date-time string, or a Unix timestamp (number) for DateTime.
GraphQLError: Value is not a valid Date: "2021-02-29"
Invalid date string (e.g., February 29 in non-leap year) passed as input
fix
Validate input dates before passing to GraphQL, or ensure they are real calendar dates.
Upgrade
Version history
3.6.1latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL scalar types
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-iso-date — npm install graphql-iso-date · libregistry