wikijs-fork/server/graph/scalars/date.js

22 lines
458 B
JavaScript
Raw Normal View History

2017-08-13 18:39:07 +00:00
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)
}
})
}