date.js 458 Bytes
Newer Older
NGPixel's avatar
NGPixel committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

const gql = require('graphql')

module.exports = {
  Date: new gql.GraphQLScalarType({
    name: 'Date',
    description: 'ISO date-time string at UTC',
    parseValue(value) {
      return new Date(value)
    },
    serialize(value) {
      return value.toISOString()
    },
    parseLiteral(ast) {
      if (ast.kind !== gql.Kind.STRING) {
        throw new TypeError('Date value must be an string!')
      }
      return new Date(ast.value)
    }
  })
}