Skip to content

Commit

Permalink
fix(client): set lifting needs to be done in the nested input types #…
Browse files Browse the repository at this point in the history
…3497

Related #3497
  • Loading branch information
Jolg42 committed Sep 2, 2020
1 parent efed15d commit fbc51d5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/packages/client/src/__tests__/types/blog/index.ts
Expand Up @@ -198,6 +198,57 @@ async function main() {
type LikeUpdateIdType = LikeUpdateManyArgs['data']['id']
type AllowsNull = null extends LikeUpdateIdType ? true : false
const allowsNull: AllowsNull = false

// check if listing of `set` is done in nested relations
// https://github.com/prisma/prisma/issues/3497
await prisma.user.update({
where: {
id: '6'
},
data: {
posts: {
update: {
data: {
title: 'something'
},
where: {
id: 'whatever'
}
},
}
},
})

await prisma.user.update({
where: {
id: '6'
},
data: {
posts: {
updateMany: {
data: {
title: 'something'
},
where: {
id: 'whatever'
}
},
}
},
})

await prisma.post.update({
where: {
id: '6'
},
data: {
author: {
update: {
name: 'something'
},
}
},
})
}

main().catch((e) => {
Expand Down
6 changes: 5 additions & 1 deletion src/packages/client/src/runtime/transformDmmf.ts
Expand Up @@ -171,7 +171,11 @@ function transformInputTypes(document: DMMF.Document): DMMF.Document {
}

// add union transformation, lift `set` up in both `update` and `updateMany` types
if (inputType.name.endsWith('UpdateInput') || inputType.name.endsWith('UpdateManyMutationInput')) {
if (inputType.name.endsWith('UpdateInput') || inputType.name.endsWith('UpdateManyMutationInput') ||
// lifting needs to be done in the nested input types https://github.com/prisma/prisma/issues/3497
(inputType.name.includes('UpdateWithout') && inputType.name.endsWith('DataInput')) ||
inputType.name.endsWith('UpdateManyDataInput')
) {
inputType.isUpdateType = true
for (const field of inputType.fields) {
const fieldInputTypeName = field.inputType[0].type.toString()
Expand Down

0 comments on commit fbc51d5

Please sign in to comment.