Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Decimal scalar #96

Merged
merged 12 commits into from
Jul 28, 2021

Conversation

iddan
Copy link
Collaborator

@iddan iddan commented Jul 5, 2021

closes #94
This PR includes copied code from https://github.com/unlight/prisma-graphql-type-decimal with attribution

TODO

  • docs
  • tests

@iddan iddan changed the title Feature/decimal Add Decimal Type Jul 5, 2021
@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2021

Codecov Report

Merging #96 (f003945) into main (67ce824) will increase coverage by 0.10%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main      #96      +/-   ##
==========================================
+ Coverage   45.26%   45.37%   +0.10%     
==========================================
  Files          28       29       +1     
  Lines         433      443      +10     
  Branches       85       86       +1     
==========================================
+ Hits          196      201       +5     
- Misses        217      222       +5     
  Partials       20       20              

@iddan iddan changed the title Add Decimal Type feat: add support for Decimal scalar Jul 5, 2021
@jasonkuhrt
Copy link
Contributor

@iddan will need some rebasing

@lvauvillier
Copy link
Contributor

Hi @iddan, @jasonkuhrt. Prisma client already use decimal.js internally.
We dont need to add it as dependency and use the same version as Prisma.

import { Prisma } from "@prisma/client";

Prisma.Decimal(value);

@iddan
Copy link
Collaborator Author

iddan commented Jul 8, 2021

The problem is Prisma is not available when using @prisma/client as a lib dependency

@jasonkuhrt
Copy link
Contributor

@iddan not sure what you mean?

@iddan
Copy link
Collaborator Author

iddan commented Jul 10, 2021

When I tried to use Prisma.Decimal the tests failed as @prisma/client doesn’t have a Prisma member until you run prisma generate

@jasonkuhrt
Copy link
Contributor

@iddan Ah I see. That technically should be acceptable since NP is not usable until PC has been generated anyways. Still, let's pin to our own version of decimal.js because its the correct thing to do--deps should not be implicit generally speaking.

Also we [will] test and support a set of Prisma versions for this kind reason. We should/will know from tests if the decimal JS we use and the one used by PC is not compatible ever one day.

@iddan
Copy link
Collaborator Author

iddan commented Jul 11, 2021

Is there an action item for me for this PR to get merged?

Copy link
Contributor

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Also looks like prettier fix is needed after my GH suggest commit sorry :)

src/entrypoints/scalars.ts Outdated Show resolved Hide resolved
src/scalars/Decimal.ts Outdated Show resolved Hide resolved
src/scalars/Decimal.ts Outdated Show resolved Hide resolved
parseValue(value: decimal.Decimal.Value) {
return new decimal.Decimal(value)
},
parseLiteral(ast) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied it from prisma-graphql-type-decimal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah figured, I guess I can look up up the GraphQL package API to learn more :) just being lazy.

tests/e2e/e2e.test.ts Outdated Show resolved Hide resolved
@iddan
Copy link
Collaborator Author

iddan commented Jul 12, 2021

I will issue the comments ASAP

@jasonkuhrt
Copy link
Contributor

jasonkuhrt commented Jul 13, 2021

@iddan do you know what's up with the newly failing tests (on windows only 🤔)?

@iddan
Copy link
Collaborator Author

iddan commented Jul 13, 2021

No idea, maybe it has to do with the new Prisma release?

@jasonkuhrt
Copy link
Contributor

@iddan but you didn't touch the Prisma version in this PR did you?

CC @Jolg42 @janpio if you know of any recent windows related issues or changes let us know 🙏

@iddan
Copy link
Collaborator Author

iddan commented Jul 16, 2021

I didn’t. When I tried to update Prisma locally the tests passed on my M1 machine after failing. That’s why I think the new Prisma release broke older Prisma versions

@janpio
Copy link

janpio commented Jul 16, 2021

I am not aware of anything. Possible that Prisma changed some path handling, but that should be visible when you test your existing codebase with that version as well and not just in this PR.

(I have no indication or reproduction of the new Prisma breaking any old things, as the old packages are completely untouched and the only external dependency, the binaries, do not influence any of this - and also did not change of course)

Copy link
Contributor

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the test problem on trunk, this pr LGTM!

@jasonkuhrt
Copy link
Contributor

I will fix the snapshot failures tomorrow

@jasonkuhrt jasonkuhrt merged commit 74da7c2 into graphql-nexus:main Jul 28, 2021
@iddan iddan deleted the feature/decimal branch July 28, 2021 15:06
github-actions bot pushed a commit that referenced this pull request Jan 7, 2023
## 1.0.0 (2023-01-07)

### ⚠ BREAKING CHANGES

* **deps:** update dependency graphql to v16

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Rostislav Simonik <rostislav.simonik@technologystudio.sk>
* scalars module only exports named exports (#187)
* support latest Prisma (#164)
* no types namespace (#130)
* remove support for prisma 2.17
* support prisma 2.30 (#114)
* Prisma Int @id maps to GraphQL Int  (#23)
* better names, auto-import friendly, jsdoc (#12)
* validate that peer dep requirements are met
* **deps:** nexua and @prisma/client are peer dependencies
* hello world

### Features

* add bytes scalar support ([#75](#75)) ([88fd092](88fd092))
* add default resolver for relation fields ([#25](#25)) ([4f5cd70](4f5cd70))
* add nexus_prisma bin for =<2.17 prisma users ([469c9e9](469c9e9))
* add nexusPrisma default and named export ([704f07c](704f07c))
* add peer dep support for prisma 2.18.x ([2e898ab](2e898ab))
* add support for BigInt scalar ([#56](#56)) ([67ce824](67ce824))
* add support for Decimal scalar ([#96](#96)) ([74da7c2](74da7c2))
* add support for reading configuration at generation time ([#27](#27)) ([275e03f](275e03f))
* control rejectOnNotFound client setting ([#135](#135)) ([01daf38](01daf38))
* **deps:** nexua and @prisma/client are peer dependencies ([b28217b](b28217b))
* emit model scalar fields ([#5](#5)) ([3a0a75a](3a0a75a))
* esm support ([#127](#127)) ([eec4932](eec4932))
* gentime setting for output directory ([#166](#166)) ([83889bf](83889bf))
* hello world ([9667cd0](9667cd0))
* Json & DateTime custom scalar support ([#9](#9)) ([df51143](df51143)), closes [#8](#8)
* Prisma Int [@id](https://github.com/id) maps to GraphQL Int  ([#23](#23)) ([624c745](624c745))
* settings system for runtime & gentime ([#42](#42)) ([ef76e45](ef76e45))
* **settings:** allow customization of prisma client import ([#49](#49)) ([c8b5f6c](c8b5f6c))
* **settings:** allow disable jsdoc guide ([#136](#136)) ([9418649](9418649))
* support latest Prisma ([#164](#164)) ([594699d](594699d))
* support prisma 2.30 ([#114](#114)) ([b7c7927](b7c7927))
* support prisma up to 2.24 ([#70](#70)) ([2704ff2](2704ff2))
* support prisma up to 3 ([#147](#147)) ([0020742](0020742))
* support projecting enums ([#18](#18)) ([1c1cd13](1c1cd13))
* turn prisma client on graphql context validation into a formal check ([#180](#180)) ([72817f1](72817f1))
* Update official Prisma support up to 2.27 ([#100](#100)) ([db1010d](db1010d))
* Use JSONResolver for Json scalar ([#231](#231)) ([e4143ac](e4143ac))
* validate that peer dep requirements are met ([7976bf5](7976bf5))

### improve

* better names, auto-import friendly, jsdoc ([#12](#12)) ([6e395b9](6e395b9))
* no types namespace ([#130](#130)) ([cbe3df8](cbe3df8))
* remove support for prisma 2.17 ([e007721](e007721))

### Refactoring

* peer dep failure state labels ([03d3c64](03d3c64))
* resolver "constraints" ([#165](#165)) ([3c9991b](3c9991b))
* **tests:** use kont for tests ([#149](#149)) ([1218c7e](1218c7e))

### Documentation

* "which should I use" guide ([599b76d](599b76d))
* add jsdoc for $settings ([#90](#90)) ([98a2267](98a2267))
* add missing issue reference ([eefa884](eefa884))
* architecture diagram ([5f4970f](5f4970f)), closes [#7](#7)
* cover projecting 1-to-1 relations ([#32](#32)) ([bb70ea4](bb70ea4))
* **jsdoc:** docPropagation docs ([#55](#55)) ([5b4e5e6](5b4e5e6))
* list enum members in jsdoc ([#92](#92)) ([d806d56](d806d56))
* mention patch ver support policy ([8e61651](8e61651))
* peer deps validation ([4992741](4992741)), closes [#2](#2)
* **readme:** adjust readiness disclaimer ([0e94cea](0e94cea))
* **readme:** remove now-resolved limitation caveat ([b5fed98](b5fed98))
* setup hello world nextra site ([784705c](784705c))
* update to nextra 2.0.0 ([#232](#232)) ([fccffd5](fccffd5))
* update to nexus@^1.1 api ([#95](#95)) ([1d31a76](1d31a76))
* **website:** fix links in docs ([#144](#144)) ([abd56f2](abd56f2))

### Testing

* **e2e:** adjust kitchen-sink snapshot ([#234](#234)) ([f831369](f831369))
* **e2e:** adjust ts-node-import-error snapshot ([#230](#230)) ([e464f2f](e464f2f))
* extract hardcoded package.json declarations to fixtures ([#309](#309)) ([8cebf8a](8cebf8a))

### chore

* **deps:** update dependency graphql to v16 ([#256](#256)) ([b6678a4](b6678a4))

### Bug fixes

* add lodash as production dep ([627aa54](627aa54)), closes [#107](#107)
* bring back support for jest ([1705a54](1705a54)), closes [#137](#137)
* **deps:** update dependency @reach/skip-nav to v0.18.0 ([#300](#300)) ([1ece744](1ece744))
* **deps:** update dependency @types/node to v18.11.17 ([#324](#324)) ([86a6c4d](86a6c4d))
* **deps:** update dependency debug to ^4.3.4 ([#289](#289)) ([53a5b47](53a5b47))
* **deps:** update dependency decimal.js to ^10.4.2 ([#301](#301)) ([38d02f6](38d02f6))
* **deps:** update dependency decimal.js to ^10.4.3 ([#325](#325)) ([21cea98](21cea98))
* **deps:** update dependency dotenv to ^9.0.2 ([#326](#326)) ([fca26b0](fca26b0))
* **deps:** update dependency fs-jetpack to v5 ([#255](#255)) ([7fdb71c](7fdb71c))
* **deps:** update dependency graphql-scalars to ^1.20.1 ([#302](#302)) ([38d47d6](38d47d6))
* **deps:** update dependency kleur to ^4.1.5 ([#290](#290)) ([3c2310f](3c2310f))
* **deps:** update dependency nextra to v2.0.0-beta.41 ([#273](#273)) ([a523891](a523891))
* **deps:** update dependency nextra-theme-docs to v2.0.0-beta.41 ([#274](#274)) ([73f99bf](73f99bf))
* **deps:** update dependency semver to ^7.3.8 ([#291](#291)) ([1cbfb25](1cbfb25))
* **deps:** update dependency tslib to ^2.4.1 ([#303](#303)) ([ec603b0](ec603b0))
* **deps:** update dependency typescript to v4.9.4 ([#251](#251)) ([bb3d9d7](bb3d9d7))
* **deps:** update nextra packages to v2.0.1 ([#316](#316)) ([f3923e2](f3923e2))
* **deps:** update nextra packages to v2.0.2 ([#346](#346)) ([ee97081](ee97081))
* **deps:** update nextra packages to v2.0.3 ([#349](#349)) ([84170d1](84170d1))
* description type should not be null ([#24](#24)) ([cffc94d](cffc94d))
* **docs:** update custom settings example ([#215](#215)) ([8b56ec9](8b56ec9))
* endent via dedent introduces unexpected newlines on Windows ([#51](#51)) ([2447f56](2447f56))
* graphql peerDependency ([#233](#233)) ([0086763](0086763))
* grpahql and floggy dependencies ([#188](#188)) ([774624f](774624f))
* handle multiline prisma docs ([#134](#134)) ([f9e2f2e](f9e2f2e))
* import path on windows ([#145](#145)) ([4699b90](4699b90))
* import prisma client for instanceof check using configured path ([#62](#62)) ([b796689](b796689))
* list def typing ([#77](#77)) ([72cc944](72cc944))
* module `fs-jetpack` not found ([#11](#11)) ([4f83b26](4f83b26))
* ncc support ([#113](#113)) ([9c7e552](9c7e552))
* output mjs files for ES modules support ([#192](#192)) ([cf59aae](cf59aae))
* remove bad prisma client on ctx check & export $settings ([#60](#60)) ([60a77cd](60a77cd))
* remove colors from the the result to fix the local test ([#225](#225)) ([684fa20](684fa20))
* remove lingering console.log ([d16f763](d16f763))
* resolve path ~ when checking if can import at @prisma/client ([#104](#104)) ([8eee072](8eee072))
* scalars module only exports named exports ([#187](#187)) ([5223f9e](5223f9e))
* setup nodejs 14 for publishing job on ci ([4cbb0de](4cbb0de))
* typegen guards for undefined relations ([#126](#126)) ([a27fc1a](a27fc1a))
* update prisma client dep to 3 ([#148](#148)) ([fa58349](fa58349))
* use import id @prisma/client by default when possible ([#88](#88)) ([5599a65](5599a65))

### CI

* add pull request workflow documentation build commit status check ([#314](#314)) ([4522e1d](4522e1d))
* configure renovate config to update only the lock file for prisma packages ([#344](#344)) ([3560a41](3560a41))
* configure renovate to automerge minor and patch chore(deps) ([#284](#284)) ([2022809](2022809))
* extract tests into reusable workflow and refactor releases ([#345](#345)) ([27e99a8](27e99a8))
* fix package version ([#317](#317)) ([4e02312](4e02312))
* group nextra packages for renovate upgrades ([#315](#315)) ([21471e8](21471e8))
* ignore execa from renovate updates due exclusive esm support ([#337](#337)) ([99110c8](99110c8))
* refactor tests to use local database ([#311](#311)) ([7559995](7559995))
* reflect local database for tests in trunk github actions workflow ([#312](#312)) ([8bfd561](8bfd561))
* switch dependencies into dev dependencies in tests ([#319](#319)) ([11ee750](11ee750))
* unify trunk and pull request github actions workflow ([#313](#313)) ([6a73b25](6a73b25))
* update renovate config to use version range to ignore packages migrated to pure esm ([#343](#343)) ([23ed616](23ed616))
@rostislav-simonik-nexus-prisma-admin
Copy link
Collaborator

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Decimal scalar
6 participants