Skip to content

waitandseeagency/graphql-type-datetime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •