Skip to content

Commit

Permalink
fix(client): Fix #4442 (#4811)
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Dec 29, 2020
1 parent 88fae09 commit 12780e8
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 314 deletions.
@@ -0,0 +1 @@
dev-tmp.db
Binary file not shown.
@@ -0,0 +1,92 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["uncheckedScalarInputs"]
}

datasource db {
provider = "sqlite"
url = "file:dev.db"
}

model User {
id Int @id @default(autoincrement())
uuid String @default(uuid())
email String @unique
firstName String
lastName String
password String
status Boolean @default(true)
locked Boolean @default(false)
public Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
trips Trip[]
activities UsersToActivities[]
}

model Trip {
id Int @id @default(autoincrement())
uuid String @default(uuid())
userId Int
name String
description String?
public Boolean
dateFrom DateTime
dateTo DateTime
adults Int
children Int? @default(0)
infants Int? @default(0)
backgroundUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id])
activities Activity[]
@@unique([userId, id])
}

model Activity {
id Int @id @default(autoincrement())
uuid String @default(uuid())
tripId Int
activityTypeId Int
name String
description String?
location String
date DateTime
timezone String
public Boolean
maxPeople Int? @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
trip Trip @relation(fields: [tripId], references: [id])
activityType ActivityType @relation(fields: [activityTypeId], references: [id])
users UsersToActivities[]
@@unique([tripId, id])
}

model ActivityType {
id Int @id @default(autoincrement())
uuid String @default(uuid())
name String
type String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
activities Activity[]
}

model UsersToActivities {
userId Int
activityId Int
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
activity Activity @relation(fields: [activityId], references: [id])
@@id([userId, activityId])
}
@@ -0,0 +1,96 @@
import { getTestClient } from '../../../../utils/getTestClient'

test('uncheckedScalarInputs validation', async () => {
expect.assertions(1)
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()

try {
await prisma.trip.create({
data: {
name: 'Trip 1',
description: 'This is a description',
public: false,
dateFrom: new Date('2020-12-29T10:15:16.495Z'),
dateTo: new Date('2020-12-29T10:15:16.495Z'),
adults: 12,
backgroundUrl: 'https://duckduckgo.com',
userId: 1,
activities: {
create: [
{
name: 'Activity1',
description: 'This is activity 1',
location: 'Some location',
date: new Date('2020-12-29T10:15:16.495Z'),
public: false,
timezone: 'Europe/Berlin',
maxPeople: 1,
activityTypeId: 1,
tripId: 1,
},
],
},
},
})
} catch (e) {
expect(e).toMatchInlineSnapshot(`
Invalid \`prisma.trip.create()\` invocation in
/client/src/__tests__/integration/errors/uncheckedScalarValidation/test.ts:9:23
6 const prisma = new PrismaClient()
7
8 try {
→ 9 await prisma.trip.create({
data: {
name: 'Trip 1',
description: 'This is a description',
public: false,
dateFrom: new Date('2020-12-29T10:15:16.495Z'),
dateTo: new Date('2020-12-29T10:15:16.495Z'),
adults: 12,
backgroundUrl: 'https://duckduckgo.com',
userId: 1,
activities: {
create: [
{
name: 'Activity1',
description: 'This is activity 1',
location: 'Some location',
date: new Date('2020-12-29T10:15:16.495Z'),
public: false,
timezone: 'Europe/Berlin',
maxPeople: 1,
activityTypeId: 1,
tripId: 1
~~~~~~
}
]
}
}
})
Unknown arg \`tripId\` in data.activities.create.0.tripId for type ActivityUncheckedCreateWithoutTripInput. Did you mean \`id\`? Available args:
type ActivityUncheckedCreateWithoutTripInput {
id?: Int
uuid?: String
activityTypeId: Int
name: String
description?: String | Null
location: String
date: DateTime
timezone: String
public: Boolean
maxPeople?: Int | Null
createdAt?: DateTime
updatedAt?: DateTime
users?: UsersToActivitiesUncheckedCreateManyWithoutActivityInput
}
`)
}

prisma.$disconnect()
})
Expand Up @@ -13858,13 +13858,13 @@ export namespace Prisma {
}

export type PostCreateManyWithoutAuthorInput = {
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, XOR<PostUncheckedCreateWithoutAuthorInput, Enumerable<PostCreateWithoutAuthorInput>>>
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, Enumerable<PostCreateWithoutAuthorInput>>
connect?: Enumerable<PostWhereUniqueInput>
connectOrCreate?: Enumerable<PostCreateOrConnectWithoutauthorInput>
}

export type PostUncheckedCreateManyWithoutAuthorInput = {
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, XOR<PostUncheckedCreateWithoutAuthorInput, Enumerable<PostCreateWithoutAuthorInput>>>
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, Enumerable<PostCreateWithoutAuthorInput>>
connect?: Enumerable<PostWhereUniqueInput>
connectOrCreate?: Enumerable<PostCreateOrConnectWithoutauthorInput>
}
Expand Down Expand Up @@ -13906,7 +13906,7 @@ export namespace Prisma {
}

export type PostUpdateManyWithoutAuthorInput = {
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, XOR<PostUncheckedCreateWithoutAuthorInput, Enumerable<PostCreateWithoutAuthorInput>>>
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, Enumerable<PostCreateWithoutAuthorInput>>
connect?: Enumerable<PostWhereUniqueInput>
set?: Enumerable<PostWhereUniqueInput>
disconnect?: Enumerable<PostWhereUniqueInput>
Expand All @@ -13919,7 +13919,7 @@ export namespace Prisma {
}

export type PostUncheckedUpdateManyWithoutAuthorInput = {
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, XOR<PostUncheckedCreateWithoutAuthorInput, Enumerable<PostCreateWithoutAuthorInput>>>
create?: XOR<Enumerable<PostUncheckedCreateWithoutAuthorInput>, Enumerable<PostCreateWithoutAuthorInput>>
connect?: Enumerable<PostWhereUniqueInput>
set?: Enumerable<PostWhereUniqueInput>
disconnect?: Enumerable<PostWhereUniqueInput>
Expand All @@ -13932,13 +13932,13 @@ export namespace Prisma {
}

export type NCreateManyWithoutMInput = {
create?: XOR<Enumerable<NUncheckedCreateWithoutMInput>, XOR<NUncheckedCreateWithoutMInput, Enumerable<NCreateWithoutMInput>>>
create?: XOR<Enumerable<NUncheckedCreateWithoutMInput>, Enumerable<NCreateWithoutMInput>>
connect?: Enumerable<NWhereUniqueInput>
connectOrCreate?: Enumerable<NCreateOrConnectWithoutmInput>
}

export type NUpdateManyWithoutMInput = {
create?: XOR<Enumerable<NUncheckedCreateWithoutMInput>, XOR<NUncheckedCreateWithoutMInput, Enumerable<NCreateWithoutMInput>>>
create?: XOR<Enumerable<NUncheckedCreateWithoutMInput>, Enumerable<NCreateWithoutMInput>>
connect?: Enumerable<NWhereUniqueInput>
set?: Enumerable<NWhereUniqueInput>
disconnect?: Enumerable<NWhereUniqueInput>
Expand All @@ -13951,13 +13951,13 @@ export namespace Prisma {
}

export type MCreateManyWithoutNInput = {
create?: XOR<Enumerable<MUncheckedCreateWithoutNInput>, XOR<MUncheckedCreateWithoutNInput, Enumerable<MCreateWithoutNInput>>>
create?: XOR<Enumerable<MUncheckedCreateWithoutNInput>, Enumerable<MCreateWithoutNInput>>
connect?: Enumerable<MWhereUniqueInput>
connectOrCreate?: Enumerable<MCreateOrConnectWithoutnInput>
}

export type MUpdateManyWithoutNInput = {
create?: XOR<Enumerable<MUncheckedCreateWithoutNInput>, XOR<MUncheckedCreateWithoutNInput, Enumerable<MCreateWithoutNInput>>>
create?: XOR<Enumerable<MUncheckedCreateWithoutNInput>, Enumerable<MCreateWithoutNInput>>
connect?: Enumerable<MWhereUniqueInput>
set?: Enumerable<MWhereUniqueInput>
disconnect?: Enumerable<MWhereUniqueInput>
Expand All @@ -13970,19 +13970,19 @@ export namespace Prisma {
}

export type ManyRequiredCreateManyWithoutOneInput = {
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, XOR<ManyRequiredUncheckedCreateWithoutOneInput, Enumerable<ManyRequiredCreateWithoutOneInput>>>
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, Enumerable<ManyRequiredCreateWithoutOneInput>>
connect?: Enumerable<ManyRequiredWhereUniqueInput>
connectOrCreate?: Enumerable<ManyRequiredCreateOrConnectWithoutoneInput>
}

export type ManyRequiredUncheckedCreateManyWithoutOneInput = {
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, XOR<ManyRequiredUncheckedCreateWithoutOneInput, Enumerable<ManyRequiredCreateWithoutOneInput>>>
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, Enumerable<ManyRequiredCreateWithoutOneInput>>
connect?: Enumerable<ManyRequiredWhereUniqueInput>
connectOrCreate?: Enumerable<ManyRequiredCreateOrConnectWithoutoneInput>
}

export type ManyRequiredUpdateManyWithoutOneInput = {
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, XOR<ManyRequiredUncheckedCreateWithoutOneInput, Enumerable<ManyRequiredCreateWithoutOneInput>>>
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, Enumerable<ManyRequiredCreateWithoutOneInput>>
connect?: Enumerable<ManyRequiredWhereUniqueInput>
set?: Enumerable<ManyRequiredWhereUniqueInput>
disconnect?: Enumerable<ManyRequiredWhereUniqueInput>
Expand All @@ -13995,7 +13995,7 @@ export namespace Prisma {
}

export type ManyRequiredUncheckedUpdateManyWithoutOneInput = {
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, XOR<ManyRequiredUncheckedCreateWithoutOneInput, Enumerable<ManyRequiredCreateWithoutOneInput>>>
create?: XOR<Enumerable<ManyRequiredUncheckedCreateWithoutOneInput>, Enumerable<ManyRequiredCreateWithoutOneInput>>
connect?: Enumerable<ManyRequiredWhereUniqueInput>
set?: Enumerable<ManyRequiredWhereUniqueInput>
disconnect?: Enumerable<ManyRequiredWhereUniqueInput>
Expand Down
81 changes: 26 additions & 55 deletions src/packages/client/src/runtime/dmmf.ts
Expand Up @@ -102,27 +102,18 @@ export class DMMFClass implements DMMF.Document {
}
for (const type of inputTypes) {
for (const field of type.fields) {
const first = field.inputTypes[0].type
if (
typeof first === 'string' &&
!ScalarTypeTable[first] &&
(this.inputTypeMap[first] || this.enumMap[first])
) {
field.inputTypes[0].type =
this.inputTypeMap[first] ||
this.enumMap[first] ||
field.inputTypes[0].type
}
const second = field.inputTypes[1] && field.inputTypes[1].type
if (
typeof second === 'string' &&
!ScalarTypeTable[second] &&
(this.inputTypeMap[second] || this.enumMap[second])
) {
field.inputTypes[1].type =
this.inputTypeMap[second] ||
this.enumMap[second] ||
field.inputTypes[1].type
for (const fieldInputType of field.inputTypes) {
const fieldType = fieldInputType.type
if (
typeof fieldType === 'string' &&
!ScalarTypeTable[fieldType] &&
(this.inputTypeMap[fieldType] || this.enumMap[fieldType])
) {
fieldInputType.type =
this.inputTypeMap[fieldType] ||
this.enumMap[fieldType] ||
fieldType
}
}
}
type.fieldMap = keyBy(type.fields, 'name')
Expand All @@ -132,47 +123,27 @@ export class DMMFClass implements DMMF.Document {
for (const type of this.outputTypes.prisma) {
for (const field of type.fields) {
for (const arg of field.args) {
const first = arg.inputTypes[0].type
if (typeof first === 'string' && !ScalarTypeTable[first]) {
arg.inputTypes[0].type =
this.inputTypeMap[first] ||
this.enumMap[first] ||
arg.inputTypes[0].type
}
const second = arg.inputTypes[1] && arg.inputTypes[1].type
if (
second &&
typeof second === 'string' &&
!ScalarTypeTable[second]
) {
arg.inputTypes[1].type =
this.inputTypeMap[second] ||
this.enumMap[second] ||
arg.inputTypes[1].type
for (const argInputType of arg.inputTypes) {
const argType = argInputType.type
if (typeof argType === 'string' && !ScalarTypeTable[argType]) {
argInputType.type =
this.inputTypeMap[argType] || this.enumMap[argType] || argType
}
}
}
}
}
for (const type of this.outputTypes.model) {
for (const field of type.fields) {
for (const arg of field.args) {
const first = arg.inputTypes[0].type
if (typeof first === 'string' && !ScalarTypeTable[first]) {
arg.inputTypes[0].type =
this.inputTypeMap[first] ||
this.enumMap[first] ||
arg.inputTypes[0].type
}
const second = arg.inputTypes[1] && arg.inputTypes[1].type
if (
second &&
typeof second === 'string' &&
!ScalarTypeTable[second]
) {
arg.inputTypes[1].type =
this.inputTypeMap[second] ||
this.enumMap[second] ||
arg.inputTypes[1].type
for (const argInputType of arg.inputTypes) {
const argType = argInputType.type
if (typeof argType === 'string' && !ScalarTypeTable[argType]) {
argInputType.type =
this.inputTypeMap[argType] ||
this.enumMap[argType] ||
argInputType.type
}
}
}
}
Expand Down

0 comments on commit 12780e8

Please sign in to comment.