mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
25 lines
602 B
TypeScript
25 lines
602 B
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
import { Decimal } from 'decimal.js-light'
|
|
import { GraphQLScalarType, Kind } from 'graphql'
|
|
|
|
export const DecimalScalar = 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)
|
|
},
|
|
})
|