Registry / testing / graphql-date

graphql-date

JSON →
library1.0.3jsnpmunverified

A GraphQL custom scalar type for Date values. Version 1.0.3 is the current stable release. The package provides a simple GraphQLDate scalar that serializes, parses, and validates date strings. It is widely used in GraphQL schemas to handle dates, but is not actively maintained. Alternatives include using graphql-iso-date or the built-in graphql@14+ Date scalar.

npm install graphql-date
INSTALL
IMPORT
SIG · GRAPHQL-DATE
G
graphql-date
testingjavascriptv1.0.3
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
const GraphQLDate = require('graphql-date')
import GraphQLDate from 'graphql-date'
Package only provides CommonJS export; default import syntax may fail in ESM environments.
GraphQLDate
import GraphQLDate from 'graphql-date'
import { GraphQLDate } from 'graphql-date'
The package uses module.exports = GraphQLDate, not a named export. Use default import.
GraphQLDate
const GraphQLDate = require('graphql-date').default
const GraphQLDate = require('graphql-date')
If using TypeScript with esModuleInterop, this may be required in some configurations.

Shows creating a GraphQL schema with a date field and querying it.

const { GraphQLObjectType, GraphQLSchema, graphql } = require('graphql'); const GraphQLDate = require('graphql-date'); const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { today: { type: GraphQLDate, resolve: () => new Date().toISOString() } } }) }); graphql(schema, '{ today }').then(result => { console.log(result); });
Debug
Known issues
deprecatedgraphql-date is not actively maintained. Consider using graphql-iso-date or the built-in GraphQL Date scalar provided by graphql@14+.
fix
Switch to graphql-iso-date or use GraphQLDate from graphql@14+.
affects: >=1.0.0
gotchaThe package does not support ESM imports. Using import syntax may cause errors in Node.js or bundlers unless transpiled.
fix
Use CommonJS require() or ensure your build pipeline handles CJS to ESM conversion.
affects: >=1.0.0
gotchaGraphQLDate only accepts ISO 8601 date strings. Other date formats (e.g., Unix timestamps) will cause serialization errors.
fix
Always format dates as ISO 8601 strings before returning in resolvers.
affects: >=1.0.0
deprecatedgraphql-date does not handle timezones. All dates are treated as UTC.
fix
Use a library like graphql-iso-date which supports timezone-aware types.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'name' of undefined
Attempting to use GraphQLDate without requiring graphql as a peer dependency.
fix
Install graphql: npm install graphql
SyntaxError: Unexpected token 'export'
Using ES module import syntax in a Node.js environment without transpilation or type: module.
fix
Use require() instead: const GraphQLDate = require('graphql-date');
Expected a value of type "Date" but received: "2023-01-01T00:00:00.000Z"
The resolver returned a string instead of a Date object, or the string format is not valid ISO 8601.
fix
Ensure you return a valid ISO string or a Date object. For example: resolve: () => new Date().toISOString()
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency for GraphQL type system integration
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-date — npm install graphql-date · libregistry