GraphQL type for Prisma's Decimal scalar, wrapper around decimal.js
npm install prisma-graphql-type-decimalGraphQL type for Prisma's Decimal scalar, wrapper around decimal.js
Created because @prisma/client has bundled decimal.js
``sh
npm install prisma-graphql-type-decimal
`
Example usage with NestJS GraphQL code first approach:
`ts
import { Decimal } from '@prisma/client-runtime-utils';
import { transformToDecimal } from 'prisma-graphql-type-decimal';
import { Type, Transform } from 'class-transformer';
@ObjectType()
export class User {
/**
* Trick to avoid error when using @Field(() => GraphQLDecimal)
*/
@Field(() => GraphQLDecimal)
@Type(() => Object)
@Transform(transformToDecimal)
money: Decimal;
@Type(() => Object)
@Transform(transformToDecimal)
moneys!: Array
}
// In nested object
class Transfers {
@Type(() => Object)
@Transform(transformToDecimal)
moneys!: Array
}
class Container {
@Type(() => Transfers)
set!: Transfers;
}
``
MIT License (c) 2023