graphql-type-datetime
v0.2.4
Published
DateTime scalar type for GraphQL.js
Downloads
1,579
Readme
graphql-type-datetime
DateTime scalar type for GraphQL.js, following the ISO 8601 format.
Ex: 2018-05-28T10:26:39.359Z
Usage
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 });
Dependency
To validate and parse the date with an ISO 8601 format, this library uses Moment.js
Related
This repository is inspired by graphql-type-json and graphql-iso-date