3.0.0 • Published 1 year ago

prisma-graphql-type-decimal v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

prisma-graphql-type-decimal

GraphQL type for Prisma's Decimal scalar, wrapper around decimal.js
Created because @prisma/client has bundled decimal.js

Install

npm install prisma-graphql-type-decimal

Usage

Example usage with NestJS GraphQL code first approach:

import { Decimal } from '@prisma/client/runtime/library.js';
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<Decimal>;
}

// In nested object
class Transfers {
  @Type(() => Object)
  @Transform(transformToDecimal)
  moneys!: Array<Decimal>;
}
class Container {
  @Type(() => Transfers)
  set!: Transfers;
}

License

MIT License (c) 2023

2.0.5

1 year ago

2.0.6

1 year ago

3.0.0

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

3 years ago