Yoctol/graphql-custom-datetype

Name: graphql-custom-datetype

Owner: YOCTOL INFO INC.

Description: Custom date type for GraphQL

Forked from: soundtrackyourbrand/graphql-custom-datetype

Created: 2016-11-24 08:21:35.0

Updated: 2017-02-02 10:22:56.0

Pushed: 2017-01-25 03:35:08.0

Homepage: null

Size: 19

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Custom Date Type for GraphQL

This is a custom date type implementation for GraphQL. GraphQL does not contain a native date type but it does allow you to specify custom scalar types that serializes to strings, or other scalar types, but conforms to certain standards.

This date type accepts and outputs this format: '2015-07-24T13:15:34.814Z' which is commonly used in JSON since it is the default format used by JavaScript when serializing dates to JSON.

npm version Build Status

Usage

To use this type you in your GraphQL schema you simply install this module with npm install --save graphql-custom-datetype and use it. In the minimal example below we expose the query now that simply returns the current date and time.

The important part is that your resolve function needs to return a JavaScript Date object.

xamples/now.js

rt {
aphql,
aphQLSchema,
aphQLObjectType,
om 'graphql';
rt CustomGraphQLDateType from '..';

schema = new GraphQLSchema({
ery: new GraphQLObjectType({
name: 'Query',
fields: {
  now: {
    type: CustomGraphQLDateType,
    // Resolve fields with the custom date type to a valid Date object
    resolve: () => new Date()
  }
}



hql(schema, "{ now }")
hen(console.log)
atch(console.error);

Running this prints the current date:

bel-node examples/now.js
ta: { now: '2015-07-24T13:23:15.580Z' } }

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.