date.js 458 B

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