You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
458 B

  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. }