scalar-date.js 471 B

12345678910111213141516171819202122
  1. 'use strict'
  2. const gql = require('graphql')
  3. module.exports = {
  4. Date: new gql.GraphQLScalarType({
  5. name: 'Date',
  6. description: 'ISO date-time string at UTC',
  7. parseValue(value) {
  8. return new Date(value)
  9. },
  10. serialize(value) {
  11. return value.toISOString()
  12. },
  13. parseLiteral(ast) {
  14. if (ast.kind !== gql.Kind.STRING) {
  15. throw new TypeError('Date value must be an string!')
  16. }
  17. return new Date(ast.value)
  18. }
  19. })
  20. }