graphql-type-datetime

0.2.4 • Public • Published

graphql-type-datetime npm version

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

Readme

Keywords

Package Sidebar

Install

npm i graphql-type-datetime

Weekly Downloads

321

Version

0.2.4

License

MIT

Unpacked Size

5.06 kB

Total Files

4

Last publish

Collaborators

  • johannpinson