Registry / database / prisma-graphql-type-decimal

prisma-graphql-type-decimal

JSON →
library4.0.4jsnpmunverified

Provides a GraphQL scalar type for Prisma's Decimal scalar, wrapping decimal.js. Current stable version is 4.0.4, requires @prisma/client v7 and @prisma/client-runtime-utils v7, and GraphQL v16. It converts decimal values between Prisma's Decimal type and GraphQL. Useful when using Prisma with GraphQL code-first approaches (e.g., NestJS) to avoid serialization issues. It exports GraphQLDecimal scalar and a transformToDecimal function for class-transformer integration.

npm install prisma-graphql-type-decimal
INSTALL
IMPORT
SIG · PRISMA-GRAPHQL-TYP
P
prisma-graphql-type-decimal
databasejavascriptv4.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GraphQLDecimal
import { GraphQLDecimal } from 'prisma-graphql-type-decimal'
const { GraphQLDecimal } = require('prisma-graphql-type-decimal')
Package is ESM-only, use import syntax. For CJS, dynamic import() is required.
transformToDecimal
import { transformToDecimal } from 'prisma-graphql-type-decimal'
import { Transform } from 'prisma-graphql-type-decimal'
transformToDecimal is a named export, not to be confused with class-transformer's Transform decorator.
Decimal
import { Decimal } from '@prisma/client-runtime-utils'
import { Decimal } from 'prisma-graphql-type-decimal'
Decimal class is exported from @prisma/client-runtime-utils, not from this package.

Shows how to use GraphQLDecimal scalar and transformToDecimal with NestJS code-first approach, including Prisma Decimal import and class-transformer decorators.

import { GraphQLDecimal, transformToDecimal } from 'prisma-graphql-type-decimal'; import { Decimal } from '@prisma/client-runtime-utils'; import { ObjectType, Field, Int } from '@nestjs/graphql'; import { Type, Transform } from 'class-transformer'; @ObjectType() export class Product { @Field(() => Int) id: number; @Field(() => GraphQLDecimal) @Type(() => Object) @Transform(transformToDecimal) price: Decimal; } // Usage in resolver import { Resolver, Query } from '@nestjs/graphql'; @Resolver(() => Product) export class ProductResolver { @Query(() => [Product]) async products() { const product = new Product(); product.id = 1; product.price = new Decimal('19.99'); return [product]; } }
Debug
Known issues
gotchaImport Decimal from @prisma/client-runtime-utils, not from prisma-graphql-type-decimal
fix
Use import { Decimal } from '@prisma/client-runtime-utils'
affects: >=4.0.0
gotchaGraphQLDecimal is a named export, not default. Wrong: import GraphQLDecimal from '...'
fix
Use import { GraphQLDecimal } from 'prisma-graphql-type-decimal'
affects: >=3.0.0
breakingv4.0.0 requires @prisma/client v7 and @prisma/client-runtime-utils v7; peer dependencies changed from v6 to v7
fix
Upgrade @prisma/client and @prisma/client-runtime-utils to ^7.0.0
affects: >=4.0.0
gotchatransformToDecimal is a transform function for class-transformer, not a decorator. Do not use @Transform(transformToDecimal()) with parentheses
fix
Use @Transform(transformToDecimal) without calling it
affects: >=3.0.0
deprecatedv3.x used @prisma/client as the source for Decimal; v4 changed to @prisma/client-runtime-utils
fix
Update imports: @prisma/client-runtime-utils instead of @prisma/client
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module '@prisma/client-runtime-utils' or its corresponding type declarations.
Missing dependency or incorrect version of @prisma/client-runtime-utils
fix
Install @prisma/client-runtime-utils: npm install @prisma/client-runtime-utils@^7.0.0
TypeError: Cannot read properties of undefined (reading 'prototype')
GraphQLDecimal is imported incorrectly or not a valid GraphQL scalar type
fix
Ensure import: import { GraphQLDecimal } from 'prisma-graphql-type-decimal' and that graphql is installed
Argument of type 'Decimal' is not assignable to parameter of type 'string | number'
Using Decimal directly in GraphQL resolver without transformation
fix
Apply @Transform(transformToDecimal) decorator on the field or manually convert Decimal to string before returning
Cannot use GraphQLScalarType "GraphQLDecimal" from another module or realm.
Multiple instances of graphql package or prisma-graphql-type-decimal in the project
fix
Ensure only one version of graphql is installed (deduplicate) and use npm dedupe or yarn resolutions
Upgrade
Version history
4.0.4latest on npm
Audit
Dependencies
@prisma/clientrequiredPrisma client v7 is required for Decimal type
@prisma/client-runtime-utilsrequiredProvides the Decimal class used for runtime
graphqlrequiredGraphQL v16 is required for GraphQLScalarType
Agent activity
8 hits · last 30 days
node
8
Resources
prisma-graphql-type-decimal — npm install prisma-graphql-type-decimal · libregistry