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(client): enable ITX support for DataProxy #16005

Merged
merged 32 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bef638e
init: *
danstarns Oct 6, 2022
ad92d60
feat: add itx header and commit and rollback
danstarns Oct 7, 2022
3ca1a3f
test: skip dataproxy skip
danstarns Oct 7, 2022
861d5eb
*: space
danstarns Oct 7, 2022
ac32760
refactor: use responseToError fn
danstarns Oct 13, 2022
2cd618f
feat: allow generating client with itx support for data proxy
aqrln Oct 24, 2022
2836706
Fix error handling and schema uploading for tx start
aqrln Oct 24, 2022
d644b0c
Extract common code
aqrln Oct 24, 2022
1beca22
Remove unused import
aqrln Oct 24, 2022
2301040
Make base url handling spec-compliant
aqrln Oct 24, 2022
13f3c4c
Get tx id from a designated response field
aqrln Oct 26, 2022
06c942e
Send the correct HTTP header for tx id
aqrln Oct 26, 2022
21d93f8
add a comment
aqrln Oct 26, 2022
33033ce
Share code between engines
aqrln Oct 27, 2022
a764647
Add missing else branch
aqrln Oct 27, 2022
d5a6c45
Convert headers in more places
aqrln Oct 31, 2022
fa25353
Rework error handling
aqrln Oct 31, 2022
8d067d0
Enable more ITX tests for Data Proxy
aqrln Nov 1, 2022
29b9efc
Add new error types
aqrln Nov 2, 2022
bcfaf25
Improve wording
aqrln Nov 2, 2022
5cbc79c
refactor: error.error -> error.body
aqrln Nov 2, 2022
6088232
Save iTX base URL in Prisma Client proxy and PrismaPromise
aqrln Nov 3, 2022
48ea39c
Add check to have sensible error instead of JSON parsing failure
aqrln Nov 4, 2022
b31a947
Fix failing unit tests
aqrln Nov 8, 2022
67be8f9
Skip error snapshots on edge client
aqrln Nov 8, 2022
8387c59
remove unnecessary awaits
aqrln Nov 8, 2022
62dd7de
update non data proxy snapshots
aqrln Nov 8, 2022
c8d7c5a
Apply suggestions from code review
aqrln Nov 8, 2022
ffb4c8e
Update packages/client/tests/functional/interactive-transactions/test…
aqrln Nov 8, 2022
6428634
bump mini-proxy
aqrln Nov 8, 2022
9909ffc
Fix formatting
aqrln Nov 8, 2022
c639987
make request info structure represent only valid states
aqrln Nov 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/client/package.json
Expand Up @@ -79,7 +79,7 @@
"@prisma/instrumentation": "workspace:*",
"@prisma/internals": "workspace:*",
"@prisma/migrate": "workspace:*",
"@prisma/mini-proxy": "0.2.0",
"@prisma/mini-proxy": "0.3.0",
"@swc-node/register": "1.5.4",
"@swc/core": "1.3.14",
"@swc/jest": "0.2.23",
Expand Down
9 changes: 6 additions & 3 deletions packages/client/src/runtime/RequestHandler.ts
Expand Up @@ -69,7 +69,7 @@ function getRequestInfo(request: Request) {
}

return {
batchTransaction: transaction?.kind === 'batch' ? transaction : undefined,
transaction,
headers,
}
}
Expand All @@ -92,13 +92,16 @@ export class RequestHandler {
// TODO: pass the child information to QE for it to issue links to queries
// const links = requests.map((r) => trace.getSpanContext(r.otelChildCtx!))

return this.client._engine.requestBatch(queries, info.headers, info.batchTransaction)
const batchTransaction = info.transaction?.kind === 'batch' ? info.transaction : undefined

return this.client._engine.requestBatch(queries, info.headers, batchTransaction)
},
singleLoader: (request) => {
const info = getRequestInfo(request)
const query = String(request.document)
const interactiveTransaction = info.transaction?.kind === 'itx' ? info.transaction : undefined

return this.client._engine.request(query, info.headers)
return this.client._engine.request(query, info.headers, interactiveTransaction)
},
batchBy: (request) => {
if (request.transaction?.id) {
Expand Down
Expand Up @@ -9,6 +9,7 @@ export type PrismaPromiseBatchTransaction = {
export type PrismaPromiseInteractiveTransaction = {
kind: 'itx'
id: string
payload: unknown
}

export type PrismaPromiseTransaction = PrismaPromiseBatchTransaction | PrismaPromiseInteractiveTransaction
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/runtime/getPrismaClient.ts
Expand Up @@ -974,7 +974,7 @@ new PrismaClient({
let result: unknown
try {
// execute user logic with a proxied the client
result = await callback(transactionProxy(this, { id: info.id }))
result = await callback(transactionProxy(this, { id: info.id, payload: info.payload }))

// it went well, then we commit the transaction
await this._engine.transaction('commit', headers, info)
Expand Down
Expand Up @@ -13,8 +13,8 @@ exports[`interactive-transactions (provider=cockroachdb) batching rollback 1`] =
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0

XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
→ XX prisma.user.create(
Unique constraint failed on the fields: (\`email\`)
Expand All @@ -37,8 +37,8 @@ exports[`interactive-transactions (provider=mongodb) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0

XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
→ XX prisma.user.create(
Unique constraint failed on the constraint: \`User_email_key\`
Expand Down Expand Up @@ -69,8 +69,8 @@ exports[`interactive-transactions (provider=mysql) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0

XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
→ XX prisma.user.create(
Unique constraint failed on the constraint: \`User_email_key\`
Expand Down Expand Up @@ -101,8 +101,8 @@ exports[`interactive-transactions (provider=postgresql) batching rollback 1`] =
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0

XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
→ XX prisma.user.create(
Unique constraint failed on the fields: (\`email\`)
Expand Down Expand Up @@ -133,8 +133,8 @@ exports[`interactive-transactions (provider=sqlite) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0

XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
→ XX prisma.user.create(
Unique constraint failed on the fields: (\`email\`)
Expand Down Expand Up @@ -165,8 +165,8 @@ exports[`interactive-transactions (provider=sqlserver) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0

XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
→ XX prisma.user.create(
Unique constraint failed on the constraint: \`dbo.User\`
Expand Down