DateTime scalar type for GraphQL.js, following the ISO 8601 format.
Ex: 2018-05-28T10:26:39.359Z
This package exports a DateTime scalar GraphQL.js type:
import GraphQLDateTime from 'graphql-type-datetime';
SDL with GraphQL-tools
When using the SDL with GraphQL-tools, define GraphQLDateTime
as the resolver for the appropriate scalar type in your schema:
import { makeExecutableSchema } from 'graphql-tools';
import GraphQLDateTime from 'graphql-type-datetime';
const typeDefs = `
scalar DateTime
type MyType {
myField: DateTime
}
# ...
`;
const resolvers = {
DateTime: GraphQLDateTime,
};
export default makeExecutableSchema({ typeDefs, resolvers });
To validate and parse the date with an ISO 8601 format, this library uses Moment.js
This repository is inspired by graphql-type-json and graphql-iso-date