-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21c69bb
commit 464b494
Showing
11 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/packages/client/src/__tests__/runtime-tests/middlewares-manipulation/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!dev.db |
Binary file added
BIN
+44 KB
src/packages/client/src/__tests__/runtime-tests/middlewares-manipulation/dev.db
Binary file not shown.
56 changes: 56 additions & 0 deletions
56
src/packages/client/src/__tests__/runtime-tests/middlewares-manipulation/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { PrismaClient } = require('@prisma/client') | ||
const assert = require('assert') | ||
|
||
module.exports = async () => { | ||
const prisma = new PrismaClient() | ||
|
||
let theParams | ||
let firstCall = true | ||
prisma.use(async (params, fetch) => { | ||
theParams = JSON.parse(JSON.stringify(params)) // clone | ||
if (firstCall) { | ||
params.args = { | ||
where: { | ||
email: 'asdasd', // this user doesn't exist | ||
}, | ||
} | ||
firstCall = false | ||
} | ||
const result = await fetch(params) | ||
return result | ||
}) | ||
|
||
prisma.use(async (params, fetch) => { | ||
const result = await fetch(params) | ||
if (result.length > 0) { | ||
result[0].name += '2' // make sure that we can change the result | ||
} | ||
return result | ||
}) | ||
|
||
const users = await prisma.user.findMany() | ||
|
||
assert.deepEqual(theParams, { | ||
dataPath: [], | ||
runInTransaction: false, | ||
action: 'findMany', | ||
model: 'User', | ||
}) | ||
|
||
assert.deepEqual(users, []) | ||
|
||
const users2 = await prisma.user.findMany() | ||
assert.deepEqual(users2, [ | ||
{ | ||
email: 'a@a.de', | ||
id: '576eddf9-2434-421f-9a86-58bede16fd95', | ||
name: 'Alice2', | ||
}, | ||
]) | ||
|
||
prisma.disconnect() | ||
} | ||
|
||
if (require.main === module) { | ||
module.exports() | ||
} |
3 changes: 3 additions & 0 deletions
3
src/packages/client/src/__tests__/runtime-tests/middlewares-manipulation/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"shouldSucceed": true | ||
} |
13 changes: 13 additions & 0 deletions
13
src/packages/client/src/__tests__/runtime-tests/middlewares-manipulation/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "my-prisma-project", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
src/packages/client/src/__tests__/runtime-tests/middlewares-manipulation/schema.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
datasource db { | ||
provider = "sqlite" | ||
url = "file:dev.db" | ||
default = true | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
experimentalFeatures = ["aggregations"] | ||
} | ||
|
||
// / User model comment | ||
model User { | ||
id String @default(uuid()) @id | ||
email String @unique | ||
// / name comment | ||
name String? | ||
posts Post[] | ||
} | ||
|
||
model Post { | ||
id String @default(cuid()) @id | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
published Boolean | ||
title String | ||
content String? | ||
authorId String? @map("author") | ||
author User? @relation(fields: [authorId], references: [id]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters