import { CustomScalar , Scalar } from '@nestjs/graphql' ; import { Decimal } from 'decimal.js' ; import { Kind , ValueNode } from 'graphql' ; @ Scalar ( 'Decimal' , ( ) => Decimal ) export class DecimalScalar implements CustomScalar < string , Decimal > { public description : string ; public parseLiteral ( ast ) { if ( ast . kind === Kind . STRING ) { return new Decimal ( ast . value ) ; } return null ; } public parseValue ( value ) { return new Decimal ( value ) ; } public serialize ( value ) { if ( typeof value === 'string' ) return value ; return value . toFixed ( ) ; } }