forked from mickhansen/graphql-sequelize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISO date format support (mickhansen#621)
* ISO date format support * Remove yarn.lock * Revert DATEONLY to String and add DateType to src/index * Missed the DATEONLY test description on revert.
- Loading branch information
1 parent
d682a1b
commit b92521c
Showing
6 changed files
with
71 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
GraphQLScalarType | ||
} from 'graphql'; | ||
|
||
/** | ||
* A special custom Scalar type for Dates that converts to a ISO formatted string | ||
* @param {String} options.name: | ||
* @param {String} options.description: | ||
* @param {Date} options.serialize(d) | ||
* @param {String} parseValue(value) | ||
* @param {Object} parseLiteral(ast) | ||
*/ | ||
export default new GraphQLScalarType({ | ||
name: 'Date', | ||
description: 'A special custom Scalar type for Dates that converts to a ISO formatted string ', | ||
/** | ||
* serialize | ||
* @param {Date} d Date obj | ||
* @return {String} Serialised date object | ||
*/ | ||
serialize(d) { | ||
if (!d) { | ||
return null; | ||
} | ||
|
||
if (d instanceof Date) { | ||
return d.toISOString(); | ||
} | ||
return d; | ||
}, | ||
/** | ||
* parseValue | ||
* @param {String} value date string | ||
* @return {Date} Date object | ||
*/ | ||
parseValue(value) { | ||
try { | ||
if (!value) { | ||
return null; | ||
} | ||
return new Date(value); | ||
} catch (e) { | ||
return null; | ||
} | ||
}, | ||
parseLiteral(ast) { | ||
return new Date(ast.value); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters