Giter Site home page Giter Site logo

unlight / prisma-graphql-type-decimal Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 0.0 739 KB

GraphQL type for Prisma's Decimal scalar, wrapper around decimal.js

JavaScript 29.80% Shell 3.62% TypeScript 66.57%
prisma-client graphql-scalar graphql-scalars decimal-js graphql graphql-types graphql-type-scalar

prisma-graphql-type-decimal's Introduction

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

prisma-graphql-type-decimal's People

Contributors

semantic-release-bot avatar unlight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

prisma-graphql-type-decimal's Issues

Unknown decorator

Hi,

i tried to use this scalar but it keeps failing with:

Cannot determine a GraphQL output type for the "sysVersion". Make sure your class is decorated with an appropriate decorator.

This is what i did in the gql config:

import { GraphQLDecimal } from 'prisma-graphql-type-decimal';
...
    resolvers: { Decimal: GraphQLDecimal },

And here is the model:

import { GraphQLDecimal } from 'prisma-graphql-type-decimal';
import { Decimal } from '@prisma/client/runtime';
...
    @Field(() => GraphQLDecimal, {nullable:false,defaultValue:0})
    sysVersion: Decimal;

Maybe i missed something but i am stuck right now.
Any advice?

If you customize the export directory, you will not be able to import `Prisma` properly

Hi, Bro, If I customize the output directory on the schema file.

generator client {
  provider      = "prisma-client-js"
  output        = "../generated/prisma-client"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

After that, this file will state that prisma could not be found:

image

image

I'd like to avoid this mistake for this situation, and I'd appreciate any helpful suggestions

Decimal can be null

When updating Decimals, it is desirable to be available to send null, to erase the field.
This is not working because transformToDecimal is trying to transform null to decimal and it is returning an error.

As for example, on an update input, the following code is generated by prisma-nestjs-graphql:

@InputType()
Class MyUpdateInputClass {
   @Field(() => GraphQLDecimal, {nullable:true})
   @Type(() => Object)
   @Transform(transformToDecimal)
   myDecimal?: Decimal;
}

But even if the field is set with nullable true, transformToDecimal throw an error.

Getting empty Decimal property

It's not an issue!!! Just a tip.
If you use this package with "prisma-nestjs-graphql" codegen and "class-validator", add the "transform: true" option to the validation configuration.

my nestjs example

  app.useGlobalPipes(
    new ValidationPipe({
      enableDebugMessages: isDevelopment,
      skipUndefinedProperties: true,
      transform: true, // !!! important
    }),
  );

P.S.
I lost 5 hours on this

ES Module directory import causing error

With ES6 modules you can not import directories, this means that when building with es-modules we get the following error:

 Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/vercel/path0/node_modules/.pnpm/[email protected]_b5ncjt6n5eukbzjwkpw2alzg2m/node_modules/@prisma/client/runtime' is not supported resolving ES modules imported from /vercel/path0/node_modules/.pnpm/[email protected]_b5ncjt6n5eukbzjwkpw2alzg2m/node_modules/prisma-graphql-type-decimal/esm/index.mjs

This should be fixed by changing: import { Decimal } from '@prisma/client/runtime'; to import { Decimal } from '@prisma/client/runtime/index.js';

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Please update to use @prisma/[email protected]

I cannot install this package with errors below

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @prisma/[email protected]
npm ERR! node_modules/@prisma/client
npm ERR! @prisma/client@"^4.8.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @prisma/client@"3 4" from [email protected]
npm ERR! node_modules/prisma-graphql-type-decimal
npm ERR! prisma-graphql-type-decimal@"2.0.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.