Skip to content

Commit

Permalink
chore(deps): update prisma monorepo to v5 (major) (#656)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Upgrade prisma dependencies to v5
---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Rostislav Simonik <[email protected]>
  • Loading branch information
renovate[bot] and rostislav-simonik authored Aug 1, 2023
1 parent 30cd6e0 commit c19b45d
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 262 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: scripts/get-lts-versions.sh

test-latest-prisma-without-database:
name: Test with latest Prisma
name: Test
timeout-minutes: 40
needs: [get-lts-versions]

Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
DATABASE: ${{ matrix.database }}

test-latest-prisma-with-database:
name: Test with latest Prisma
name: Test
timeout-minutes: 40
needs: [get-lts-versions]

Expand Down Expand Up @@ -114,8 +114,8 @@ jobs:
env:
DATABASE: ${{ matrix.database }}

test-past-versions-with-database:
name: Test with past versions
test-bottom-versions-with-database:
name: Test
timeout-minutes: 40
needs: [get-lts-versions]

Expand All @@ -124,7 +124,7 @@ jobs:
os: ['ubuntu-latest']
node-version: ${{ fromJson(needs.get-lts-versions.outputs.matrix_last_lts_version) }}
database: ['db']
past-version: ['prisma@4.0, [email protected]', '[email protected]']
bottom-version: ['prisma@5.0, [email protected]', '[email protected]']

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -158,23 +158,23 @@ jobs:
run: yarn -s build

- name: Set E2E DB Schema
if: contains(matrix.past-version, 'prisma')
if: contains(matrix.bottom-version, 'prisma')
run: yarn -s ts-node scripts/get-e2e-db-schema --os ${{ matrix.os }} --node-version ${{ matrix.node-version }} --prisma-client-version 4.0 --github-env $GITHUB_ENV

- name: Set E2E DB Schema
if: contains(matrix.past-version, 'prisma') == false
if: contains(matrix.bottom-version, 'prisma') == false
run: yarn -s ts-node scripts/get-e2e-db-schema --os ${{ matrix.os }} --node-version ${{ matrix.node-version }} --github-env $GITHUB_ENV

- name: Install past prisma dev packages
if: contains(matrix.past-version, 'prisma')
run: yarn -s add prisma@4.0 @prisma/client@4.0 @prisma/internals@4.0 --dev
- name: Install bottom prisma dev packages
if: contains(matrix.bottom-version, 'prisma')
run: yarn -s add prisma@5.0 @prisma/client@5.0 @prisma/internals@5.0 --dev

- name: Install past prisma packages
if: contains(matrix.past-version, 'prisma')
run: yarn -s add @prisma/generator-helper@4.0
- name: Install bottom prisma packages
if: contains(matrix.bottom-version, 'prisma')
run: yarn -s add @prisma/generator-helper@5.0

- name: Install past graphql packages
if: contains(matrix.past-version, 'graphql')
- name: Install bottom graphql packages
if: contains(matrix.bottom-version, 'graphql')
run: yarn -s add graphql@^15.8.0 [email protected] --dev

#NOTE: addresses issue "npm ERR! maxAge must be a number" due picking npm version from local semantic-release
Expand All @@ -185,4 +185,4 @@ jobs:
run: yarn -s test:ci
env:
DATABASE: ${{ matrix.database }}
PAST_VERSION: ${{ matrix.past-version }}
BOTTOM_VERSION: ${{ matrix.bottom-version }}
18 changes: 1 addition & 17 deletions docs/pages/docs/features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,6 @@ model A { type A {

If a `findOne` or `findUnique` for a non-nullable Prisma field return null for some reason (e.g. data corruption in the database) then the standard [GraphQL `null` propagation](https://medium.com/@calebmer/when-to-use-graphql-non-null-fields-4059337f6fc8) will kick in.

### Prisma Client `rejectOnNotFound` Handling

Prisma Client's [`rejectOnNotFound` feature](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#rejectonnotfound) is effectively ignored by Nexus Prisma. For example if you [set `rejectOnNotFound` globally on your Prisma Client](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#enable-globally-for-findunique-and-findfirst) it will not effect Nexus Prisma when it uses Prisma Client. This is because Nexus Prisma [sets `rejectOnNotFound: false` for every `findUnique`/`findFirst`](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#remarks-2) request it sends.

The reason for this design choice is that when Nexus Prisma's logic is handling a GraphQL resolver that includes how to handle nullability issues which it has full knowledge about.

If you have a use-case for different behaviour [please open a feature request](https://github.com/prisma/nexus-prisma/issues/new?assignees=&labels=type%2Ffeat&template=10-feature.md&title=Better%20rejectOnNotFound%20Handling). Also, remember, you can always override the Nexus Prisma resolvers with your own logic ([recipe](/recipes#project-relation-with-custom-resolver-logic)).

### Related Issues

- [`#98` Always set rejectOnNotFound to false](https://github.com/prisma/nexus-prisma/issues/98)

## Prisma Schema Docs Propagation

### As GraphQL schema doc
Expand Down Expand Up @@ -598,11 +586,7 @@ This formatting logic is conservative. We are open to making it less so, in orde

## ESM Support

Nexus Prisma supports both [ESM](https://nodejs.org/api/esm.html) and CJS. There shouldn't be anything you need to "do", things should "just work". Here's the highlights of how it works though:

- We publish both a CJS and ESM build to npm.
- When the generator runs, it emits CJS code to the CJS build _and_ ESM code to the ESM build.
- Nexus Prisma CLI exists both in the ESM and CJS builds but its built to not matter which is used. That said, the package manifest is setup to run the CJS of the CLI and so that is what ends up being used in practice.
We are not supporting esm build yet, more info [here](https://github.com/graphql-nexus/nexus-prisma/discussions/693).

## Refined DX

Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ We test Node versions that are `Active LTS` and `Current`. For which versions of

We only officially support what we test.

We test Prisma Client versions `2.30.x`, `2.29.x`.
We are testing Prisma Client bottom version and the recent version but locked to the version, which has passed tests. If there is a newer release of prisma dependencies than the locked version, but it failed, we are still upgrading other dependencies and testing given changes against the locked version.

## Supported Versions Of `ts-node`

Expand All @@ -99,7 +99,7 @@ Reminder: `ts-node` is an optional peer dep required when you are working with t

### Matrix Testing Policy

We test the latest versions of `@prisma/client` against Node 18, 16 and 14 on Ubuntu, macOS, and Windows while past versions of `@prisma/client` are tested only against Node 18 on Ubuntu. We do this to keep the CI test matris reasonable as the number of past `@prisma/client` versions supported could grow long.
We test the latest versions of `@prisma/client` against `Active LTS` and `Current` Node on Ubuntu, macOS, and Windows while bottom versions of `@prisma/client` are tested only against `Current` Node on Ubuntu. We do this to keep the CI test matrix reasonable as the number of execute tests could grow many times over.

### Patch Version Support Policy

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"@commitlint/config-conventional": "^17.6.7",
"@homer0/prettier-plugin-jsdoc": "^7.0.3",
"@prisma-labs/prettier-config": "0.1.0",
"@prisma/client": "^4.0",
"@prisma/internals": "^4.0",
"@prisma/client": "^5.0.0",
"@prisma/internals": "^5.0.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@types/debug": "^4.1.8",
Expand Down Expand Up @@ -110,7 +110,7 @@
"nodemon": "^3.0.1",
"object-hash": "^3.0.0",
"prettier": "3.0.0",
"prisma": "^4.0",
"prisma": "^5.0.0",
"read-pkg-up": "7.0.1",
"slug": "^8.2.3",
"strip-ansi": "6",
Expand All @@ -126,7 +126,7 @@
},
"prettier": "@prisma-labs/prettier-config",
"peerDependencies": {
"@prisma/client": "^4.0",
"@prisma/client": "^5.0.0",
"graphql": "^15.0.0 || ^16.0.0",
"nexus": "1.2.0 || ^1.3.0",
"ts-node": "^10.9.1"
Expand All @@ -137,7 +137,7 @@
}
},
"dependencies": {
"@prisma/generator-helper": "^4.0",
"@prisma/generator-helper": "^5.0.0",
"debug": "^4.3.4",
"decimal.js": "^10.4.3",
"dindist": "^1.0.2",
Expand Down
16 changes: 1 addition & 15 deletions src/generator/ModuleGenerators/JS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Nexus from 'nexus'
import { NexusEnumTypeConfig, NexusListDef, NexusNonNullDef, NexusNullDef } from 'nexus/dist/core'
import { inspect } from 'util'

import type { DMMF } from '@prisma/client/runtime'
import type { DMMF } from '@prisma/client/runtime/library'

import { MaybePromise, RecordUnknown, Resolver } from '../../helpers/utils'
import { Messenger } from '../../lib/messenger'
Expand Down Expand Up @@ -340,20 +340,6 @@ export const nexusResolverFromPrismaField = (
const findUnique = prismaModel.findUnique as (query: unknown) => MaybePromise<unknown>
const result: unknown = findUnique({
where: whereUnique,
/**
*
* The user might have configured Prisma Client globally to rejectOnNotFound.
* In the context of this Nexus Prisma managed resolver, we don't want that setting to
* be a behavioral factor. Instead, Nexus Prisma has its own documented rules about the logic
* it uses to project nullability from the database to the api.
*
* More details about this design can be found in the README.
*
* References:
*
* - https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#rejectonnotfound
*/
rejectOnNotFound: false,
})

// @ts-expect-error Only known at runtime
Expand Down
2 changes: 1 addition & 1 deletion src/generator/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs-jetpack'
import * as Path from 'path'

import { DMMF } from '@prisma/client/runtime'
import { DMMF } from '@prisma/client/runtime/library'

import { d } from '../helpers/debugNexusPrisma'
import { Module } from './helpers/types'
Expand Down
2 changes: 1 addition & 1 deletion src/generator/helpers/JSDocTemplates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dedent from 'dindist'

import { DMMF } from '@prisma/client/runtime'
import { DMMF } from '@prisma/client/runtime/library'

import { PrismaDocumentation } from '../../lib/prisma-documentation'
import type { Settings } from '../Settings'
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DMMF } from '@prisma/client/runtime'
import { DMMF } from '@prisma/client/runtime/library'
import dedent from 'dindist'
import kleur from 'kleur'
import ono from 'ono'
Expand Down
2 changes: 1 addition & 1 deletion src/lib/prisma-dmmf/PrismaDmmf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DMMF } from '@prisma/client/runtime'
import { DMMF } from '@prisma/client/runtime/library'

export type DocumentableNode = DMMF.Model | DMMF.Field | DMMF.DatamodelEnum

Expand Down
2 changes: 1 addition & 1 deletion src/lib/prisma-utils/whereUniqueInput.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DMMF } from '@prisma/client/runtime'
import { DMMF } from '@prisma/client/runtime/library'
import { pick } from 'lodash'
import { inspect } from 'util'
import { RecordUnknown } from '../../helpers/utils'
Expand Down
97 changes: 50 additions & 47 deletions tests/e2e/kitchen-sink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ctx = konn()

beforeEach(async () => {
await ctx.fixture.useAsync(Path.join(__dirname, 'fixtures/kitchen-sink'))
if (process.env.PAST_VERSION && process.env.PAST_VERSION.indexOf('prisma') !== -1) {
if (process.env.BOTTOM_VERSION && process.env.BOTTOM_VERSION.indexOf('prisma') !== -1) {
await ctx.packageJson.mergeAsync({
devDependencies: {
typescript: '4.7.4',
Expand Down Expand Up @@ -369,6 +369,7 @@ it('A full-featured project type checks, generates expected GraphQL schema, and
[
new Promise((res) =>
serverProcess.stdout!.on('data', (data: Buffer) => {
console.log(data.toString())
if (data.toString().match(SERVER_READY_MESSAGE)) res('server_started')
}),
),
Expand All @@ -381,37 +382,29 @@ it('A full-featured project type checks, generates expected GraphQL schema, and
`server was not ready after 10 seconds. The output from child process was:\n\n${serverProcess.stdio.toString()}\n\n`,
)
}
d(`starting client queries`)
const data = await ctx.graphQLClient.request(gql`
query {
bars {
foo {
JsonManually
DateTimeManually
BytesManually
DecimalManually
BigIntManually
someEnumA
someJsonField
someDateTimeField
someBytesField
someDecimalField
someBigIntField
try {
d(`starting client queries`)
const data = await ctx.graphQLClient.request(gql`
query {
bars {
foo {
JsonManually
DateTimeManually
BytesManually
DecimalManually
BigIntManually
someEnumA
someJsonField
someDateTimeField
someBytesField
someDecimalField
someBigIntField
}
}
}
}
`)

d(`stopping server`)

serverProcess.cancel()
// On Windows the serverProcess never completes the promise so we do an ugly timeout here
// and rely on jest --forceExit to terminate the process

await timeoutRace([serverProcess], 2_000)
`)

d(`stopped server`)
expect(data).toMatchInlineSnapshot(`
expect(data).toMatchInlineSnapshot(`
{
"bars": [
{
Expand All @@ -436,23 +429,33 @@ it('A full-featured project type checks, generates expected GraphQL schema, and
}
`)

const {
bars: [{ foo }],
} = data as {
bars: [
{
foo: Record<string, unknown>
},
]
}
const {
bars: [{ foo }],
} = data as {
bars: [
{
foo: Record<string, unknown>
},
]
}

expect(foo.JsonManually).toBeNull()
expect(foo.DateTimeManually).toBeNull()
expect(foo.BytesManually).toBeNull()
expect(foo.BigIntManually).toBeNull()
expect(typeof foo.someEnumA).toEqual('string')
expect(typeof foo.someJsonField).toEqual('object')
expect(typeof foo.someDateTimeField).toEqual('string')
expect(typeof foo.someBytesField).toEqual('object')
expect(typeof GQLScalars.BigIntResolver.parseValue(foo.someBigIntField)).toEqual('bigint')
expect(foo.JsonManually).toBeNull()
expect(foo.DateTimeManually).toBeNull()
expect(foo.BytesManually).toBeNull()
expect(foo.BigIntManually).toBeNull()
expect(typeof foo.someEnumA).toEqual('string')
expect(typeof foo.someJsonField).toEqual('object')
expect(typeof foo.someDateTimeField).toEqual('string')
expect(typeof foo.someBytesField).toEqual('object')
expect(typeof GQLScalars.BigIntResolver.parseValue(foo.someBigIntField)).toEqual('bigint')
} finally {
d(`stopping server`)

serverProcess.cancel()
// On Windows the serverProcess never completes the promise so we do an ugly timeout here
// and rely on jest --forceExit to terminate the process

await timeoutRace([serverProcess], 2_000)
d(`stopped server`)
}
}, 120_000)
33 changes: 0 additions & 33 deletions tests/integration/__snapshots__/rejectOnNotFound.test.ts.snap

This file was deleted.

Loading

0 comments on commit c19b45d

Please sign in to comment.