Registry / testing / graphql-date-scalars

graphql-date-scalars

JSON →
library0.2.0jsnpmunverified

GraphQL scalars for Date, DateTime, and Time formats in compliance with ISO 8601 (YYYY-MM-DD, YYYY-MM-DDTHH:MM:SSZ, HH:MM:SSZ). Version 0.2.0 supports both GraphQL v15 and v16, ships TypeScript definitions, and requires Node >=14. Unlike graphql-iso-date (deprecated library this was forked from), this package uses plain resolvers instead of GraphQL scalar interface, making it simpler to integrate. It provides parse/serialize methods for direct usage outside of GraphQL resolvers. Release cadence is ad-hoc with no recent updates.

npm install graphql-date-scalars
INSTALL
IMPORT
SIG · GRAPHQL-DATE-SCALA
G
graphql-date-scalars
testingjavascriptv0.2.0
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.

DateScalar
import { DateScalar } from 'graphql-date-scalars'
import { DateScalar } from 'graphql-date-scalars/Date'
Use named import, not deep path. The library does not provide a default export.
DateTimeScalar
import { DateTimeScalar } from 'graphql-date-scalars'
const { DateTimeScalar } = require('graphql-date-scalars')
Package is ESM-only (type: module in package.json). CommonJS require will fail.
TimeScalar
import { TimeScalar } from 'graphql-date-scalars'
TimeScalar is also available via named import. No known wrong import pattern.

Basic Apollo Server setup with Date, Time, and DateTime scalar types using graphql-date-scalars.

import { gql, ApolloServer } from 'apollo-server'; import { DateScalar, TimeScalar, DateTimeScalar } from 'graphql-date-scalars'; const typeDefs = gql` scalar Date scalar Time scalar DateTime type Query { today: Date! now: DateTime! currentTime: Time! } `; const resolvers = { Date: DateScalar, Time: TimeScalar, DateTime: DateTimeScalar, Query: { today: () => new Date('2023-01-15'), now: () => new Date(), currentTime: () => new Date(), }, }; const server = new ApolloServer({ typeDefs, resolvers }); server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
Debug
Known issues
gotchaPackage is ESM-only; using require() will throw 'ERR_REQUIRE_ESM'.
fix
Use import syntax or switch to dynamic import().
affects: >=0.2.0
gotchaScalars output dates in ISO 8601 format but do not validate input thoroughly; invalid strings may cause runtime errors.
fix
Validate date strings before passing them to parseValue. Use a library like 'date-fns' for strict parsing.
affects: >=0.1.0
deprecatedThis package is a fork of graphql-iso-date (deprecated). graphql-iso-date used GraphQLScalarType interface; graphql-date-scalars uses plain objects for resolvers.
fix
If migrating from graphql-iso-date, replace { GraphQLDate } with { DateScalar } and use it directly as a resolver.
affects: >=0.1.0
breakingVersion 0.2.0 dropped support for GraphQL v14; only v15 and v16 are supported.
fix
Upgrade graphql dependency to ^15.0.0 || ^16.0.0.
affects: >=0.2.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require() on an ESM-only package.
fix
Change to import statement: import { DateTimeScalar } from 'graphql-date-scalars'
TypeError: DateScalar is not a GraphQL scalar
Attempting to use DateScalar with new GraphQLScalarType() or in schema language incorrectly.
fix
Use DateScalar directly in resolvers: resolvers: { Date: DateScalar }
Expected a value of type "DateTime" but received: "invalid-date"
Passing an invalid date string to a DateTime field.
fix
Ensure date strings are valid ISO 8601 (e.g., '2023-01-15T10:30:00Z').
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL scalar type definitions
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-date-scalars — npm install graphql-date-scalars · libregistry