mirror of https://github.com/requarks/wiki
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.
28 lines
667 B
28 lines
667 B
2 years ago
|
import gql from 'graphql'
|
||
|
import { DateTime } from 'luxon'
|
||
2 years ago
|
|
||
|
function parseDateTime (value) {
|
||
|
const nDate = DateTime.fromISO(value)
|
||
|
return nDate.isValid ? nDate : null
|
||
|
}
|
||
7 years ago
|
|
||
2 years ago
|
export default new gql.GraphQLScalarType({
|
||
3 years ago
|
name: 'Date',
|
||
|
description: 'ISO date-time string at UTC',
|
||
|
parseValue(value) {
|
||
2 years ago
|
if (typeof value !== 'string') {
|
||
|
throw new TypeError('Date value must be an string!')
|
||
|
}
|
||
|
return parseDateTime(value)
|
||
3 years ago
|
},
|
||
|
serialize(value) {
|
||
|
return value.toISOString()
|
||
|
},
|
||
|
parseLiteral(ast) {
|
||
|
if (ast.kind !== gql.Kind.STRING) {
|
||
|
throw new TypeError('Date value must be an string!')
|
||
7 years ago
|
}
|
||
2 years ago
|
return parseDateTime(ast.value)
|
||
3 years ago
|
}
|
||
|
})
|