mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
24 lines
525 B
TypeScript
24 lines
525 B
TypeScript
import { GraphQLScalarType, Kind } from 'graphql'
|
|
import Decimal from 'decimal.js-light'
|
|
|
|
export default new GraphQLScalarType({
|
|
name: 'Decimal',
|
|
description: 'The `Decimal` scalar type to represent currency values',
|
|
|
|
serialize(value: Decimal) {
|
|
return value.toString()
|
|
},
|
|
|
|
parseValue(value) {
|
|
return new Decimal(value)
|
|
},
|
|
|
|
parseLiteral(ast) {
|
|
if (ast.kind !== Kind.STRING) {
|
|
throw new TypeError(`${String(ast)} is not a valid decimal value.`)
|
|
}
|
|
|
|
return new Decimal(ast.value)
|
|
},
|
|
})
|